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.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#seen ⇒ Object
Returns the value of attribute seen.
-
#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.
Instance Method Summary collapse
- #cancel_ttl_timer ⇒ Object
-
#initialize(id, project_name: nil, ttl: nil) ⇒ User
constructor
A new instance of User.
- #load_data ⇒ Object
- #project_crashed(actor, reason) ⇒ Object
- #restart_ttl_timer ⇒ Object
- #state_changed(topic, state) ⇒ Object
- #ttl_expired! ⇒ Object
Constructor Details
#initialize(id, project_name: nil, ttl: nil) ⇒ User
Returns a new instance of User.
13 14 15 16 17 18 19 20 |
# File 'lib/cellect/server/user.rb', line 13 def initialize(id, project_name: nil, ttl: nil) self.id = id self.project_name = project_name self.seen = DiffSet::RandomSet.new monitor Project[project_name] @ttl = ttl load_data end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/cellect/server/user.rb', line 10 def id @id end |
#project_name ⇒ Object
Returns the value of attribute project_name.
10 11 12 |
# File 'lib/cellect/server/user.rb', line 10 def project_name @project_name end |
#seen ⇒ Object
Returns the value of attribute seen.
10 11 12 |
# File 'lib/cellect/server/user.rb', line 10 def seen @seen end |
#state ⇒ Object
Returns the value of attribute state.
10 11 12 |
# File 'lib/cellect/server/user.rb', line 10 def state @state end |
#ttl ⇒ Object
Returns the value of attribute ttl.
11 12 13 |
# File 'lib/cellect/server/user.rb', line 11 def ttl @ttl end |
#ttl_timer ⇒ Object
Returns the value of attribute ttl_timer.
11 12 13 |
# File 'lib/cellect/server/user.rb', line 11 def ttl_timer @ttl_timer end |
Instance Method Details
#cancel_ttl_timer ⇒ Object
45 46 47 48 |
# File 'lib/cellect/server/user.rb', line 45 def cancel_ttl_timer ttl_timer.cancel if ttl_timer self.ttl_timer = nil end |
#load_data ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/cellect/server/user.rb', line 22 def load_data data = Cellect::Server.adapter.load_user(project_name, id) || [] data.each do |subject_id| @seen.add subject_id end self.state = :ready restart_ttl_timer end |
#project_crashed(actor, reason) ⇒ Object
60 61 62 63 |
# File 'lib/cellect/server/user.rb', line 60 def project_crashed(actor, reason) cancel_ttl_timer terminate end |
#restart_ttl_timer ⇒ Object
40 41 42 43 |
# File 'lib/cellect/server/user.rb', line 40 def restart_ttl_timer self.ttl_timer ||= after(ttl){ ttl_expired! } ttl_timer.reset end |
#state_changed(topic, state) ⇒ Object
36 37 38 |
# File 'lib/cellect/server/user.rb', line 36 def state_changed(topic, state) restart_ttl_timer if state == :ready && ttl end |
#ttl_expired! ⇒ Object
50 51 52 53 54 |
# File 'lib/cellect/server/user.rb', line 50 def ttl_expired! debug "User #{ id } TTL expired" cancel_ttl_timer Project[project_name].async.remove_user(id) end |