Class: Aptabase::Session
- Inherits:
-
Object
- Object
- Aptabase::Session
- Defined in:
- lib/aptabase/session.rb
Overview
Session tracking with the same semantics as the other Aptabase SDKs: a session id is reused until one hour of inactivity, then rotated.
Constant Summary collapse
- TIMEOUT =
seconds
60 * 60
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(clock: -> { Time.now }) ⇒ Session
constructor
A new instance of Session.
Constructor Details
#initialize(clock: -> { Time.now }) ⇒ Session
Returns a new instance of Session.
9 10 11 12 13 14 |
# File 'lib/aptabase/session.rb', line 9 def initialize(clock: -> { Time.now }) @clock = clock @mutex = Mutex.new @id = nil @last_touched = nil end |
Instance Method Details
#id ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/aptabase/session.rb', line 16 def id @mutex.synchronize do now = @clock.call @id = generate_id(now) if @id.nil? || now - @last_touched > TIMEOUT @last_touched = now @id end end |