Class: Tempest::Cluster

Inherits:
Object
  • Object
show all
Defined in:
lib/tempest/cluster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis = 'localhost:6379') ⇒ Cluster

Returns a new instance of Cluster.



27
28
29
30
31
32
# File 'lib/tempest/cluster.rb', line 27

def initialize redis='localhost:6379'
  @redis = redis
  @_on = {}
  @loop = true
  @id = 0
end

Instance Attribute Details

#loopObject

Returns the value of attribute loop.



26
27
28
# File 'lib/tempest/cluster.rb', line 26

def loop
  @loop
end

Instance Method Details

#answer(who, action, job_id, args) ⇒ Object



49
50
51
# File 'lib/tempest/cluster.rb', line 49

def answer who, action, job_id, args
  Tempest.client(who).send action, job_id, args.to_json
end

#on(action, &block) ⇒ Object



34
35
36
# File 'lib/tempest/cluster.rb', line 34

def on action, &block
  @_on[action] = block
end

#work(queue, action, args, respond_to) ⇒ Object



53
54
55
56
57
58
# File 'lib/tempest/cluster.rb', line 53

def work queue, action, args, respond_to
  #FIXME implement the real id tactic
  @id += 1
  Tempest.client(@redis).rpush queue, [action, args, respond_to, @id].to_json
  @id
end