Class: Cellect::Server::User

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Celluloid::Logger
Defined in:
lib/cellect/server/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, workflow_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, 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

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/cellect/server/user.rb', line 10

def id
  @id
end

#seenObject

Returns the value of attribute seen.



10
11
12
# File 'lib/cellect/server/user.rb', line 10

def seen
  @seen
end

#stateObject

Returns the value of attribute state.



10
11
12
# File 'lib/cellect/server/user.rb', line 10

def state
  @state
end

#ttlObject

Returns the value of attribute ttl.



11
12
13
# File 'lib/cellect/server/user.rb', line 11

def ttl
  @ttl
end

#ttl_timerObject

Returns the value of attribute ttl_timer.



11
12
13
# File 'lib/cellect/server/user.rb', line 11

def ttl_timer
  @ttl_timer
end

#workflow_nameObject

Returns the value of attribute workflow_name.



10
11
12
# File 'lib/cellect/server/user.rb', line 10

def workflow_name
  @workflow_name
end

Instance Method Details

#cancel_ttl_timerObject



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_dataObject



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(workflow_name, id) || []
  data.each do |subject_id|
    @seen.add subject_id
  end
  self.state = :ready
  restart_ttl_timer
end

#restart_ttl_timerObject



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
  Workflow[workflow_name].async.remove_user(id)
end

#workflow_crashed(actor, reason) ⇒ Object



60
61
62
63
# File 'lib/cellect/server/user.rb', line 60

def workflow_crashed(actor, reason)
  cancel_ttl_timer
  terminate
end