Class: Cellect::Server::User
- Inherits:
-
Object
- Object
- Cellect::Server::User
- Includes:
- Celluloid, Celluloid::Logger
- Defined in:
- lib/cellect/server/user.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#seen ⇒ Object
Returns the seen subjects set.
-
#state ⇒ Object
Returns the value of attribute state.
-
#ttl ⇒ Object
Returns the value of attribute ttl.
-
#ttl_timer ⇒ Object
Returns the value of attribute ttl_timer.
-
#workflow_name ⇒ Object
Returns the value of attribute workflow_name.
Instance Method Summary collapse
-
#cancel_ttl_timer ⇒ Object
Releases the timer.
-
#initialize(id, workflow_name: nil, ttl: nil) ⇒ User
constructor
Sets up a new user with an empty seen set, then loads the actual data.
-
#load_data ⇒ Object
Load the seen subjects for a user and restarts the TTL.
-
#restart_ttl_timer ⇒ Object
(Re)starts the inactivity countdown.
-
#ttl_expired! ⇒ Object
Removes the user from inactivity.
-
#workflow_crashed(actor, reason) ⇒ Object
Handle errors and let the actor die.
Constructor Details
#initialize(id, workflow_name: nil, ttl: nil) ⇒ User
Sets up a new user with an empty seen set, then loads the actual data
15 16 17 18 19 20 21 22 |
# File 'lib/cellect/server/user.rb', line 15 def initialize(id, workflow_name: nil, ttl: nil) self.id = id self.workflow_name = workflow_name self.seen = DiffSet::RandomSet.new monitor Workflow[workflow_name] @ttl = ttl load_data end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
11 12 13 |
# File 'lib/cellect/server/user.rb', line 11 def id @id end |
#seen ⇒ Object
Returns the seen subjects set
35 36 37 |
# File 'lib/cellect/server/user.rb', line 35 def seen @seen end |
#state ⇒ Object
Returns the value of attribute state.
11 12 13 |
# File 'lib/cellect/server/user.rb', line 11 def state @state end |
#ttl ⇒ Object
Returns the value of attribute ttl.
12 13 14 |
# File 'lib/cellect/server/user.rb', line 12 def ttl @ttl end |
#ttl_timer ⇒ Object
Returns the value of attribute ttl_timer.
12 13 14 |
# File 'lib/cellect/server/user.rb', line 12 def ttl_timer @ttl_timer end |
#workflow_name ⇒ Object
Returns the value of attribute workflow_name.
11 12 13 |
# File 'lib/cellect/server/user.rb', line 11 def workflow_name @workflow_name end |
Instance Method Details
#cancel_ttl_timer ⇒ Object
Releases the timer
47 48 49 50 |
# File 'lib/cellect/server/user.rb', line 47 def cancel_ttl_timer ttl_timer.cancel if ttl_timer self.ttl_timer = nil end |
#load_data ⇒ Object
Load the seen subjects for a user and restarts the TTL
25 26 27 28 29 30 31 32 |
# File 'lib/cellect/server/user.rb', line 25 def load_data data = Cellect::Server.adapter.load_user(workflow_name, id) || [] data.each do |subject_id| @seen.add subject_id end self.state = :ready restart_ttl_timer end |
#restart_ttl_timer ⇒ Object
(Re)starts the inactivity countdown
41 42 43 44 |
# File 'lib/cellect/server/user.rb', line 41 def restart_ttl_timer self.ttl_timer ||= after(ttl){ ttl_expired! } ttl_timer.reset end |
#ttl_expired! ⇒ Object
Removes the user from inactivity
53 54 55 56 57 |
# File 'lib/cellect/server/user.rb', line 53 def ttl_expired! debug "User #{ id } TTL expired" cancel_ttl_timer Workflow[workflow_name].async.remove_user(id) end |
#workflow_crashed(actor, reason) ⇒ Object
Handle errors and let the actor die
64 65 66 67 |
# File 'lib/cellect/server/user.rb', line 64 def workflow_crashed(actor, reason) cancel_ttl_timer terminate end |