Class: Geary::Performer
- Inherits:
-
Object
- Object
- Geary::Performer
- Extended by:
- Forwardable
- Includes:
- Celluloid
- Defined in:
- lib/geary/performer.rb
Instance Method Summary collapse
- #build_connection ⇒ Object
- #configure_connection(connection_routine) ⇒ Object
- #disconnect ⇒ Object
-
#initialize(address) ⇒ Performer
constructor
A new instance of Performer.
- #perform(packet) ⇒ Object
- #reconnect(actor, reason) ⇒ Object
- #start ⇒ Object
Constructor Details
Instance Method Details
#build_connection ⇒ Object
63 64 65 |
# File 'lib/geary/performer.rb', line 63 def build_connection @gearman = @connect.call(@address) end |
#configure_connection(connection_routine) ⇒ Object
67 68 69 70 |
# File 'lib/geary/performer.rb', line 67 def configure_connection(connection_routine) @connect = connection_routine reconnect(current_actor, nil) end |
#disconnect ⇒ Object
52 53 54 55 56 |
# File 'lib/geary/performer.rb', line 52 def disconnect if @gearman @gearman.terminate if @gearman.alive? end end |
#perform(packet) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/geary/performer.rb', line 37 def perform(packet) job = JSON.parse(packet.data) job_result = nil begin worker = ::Object.const_get(job['class']).new job_result = worker.perform(*job['args']) rescue => error @gearman.async.work_exception(packet.handle, error.) else @gearman.async.work_complete(packet.handle, job_result) end end |
#reconnect(actor, reason) ⇒ Object
58 59 60 61 |
# File 'lib/geary/performer.rb', line 58 def reconnect(actor, reason) disconnect build_connection end |
#start ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/geary/performer.rb', line 20 def start @gearman.can_do('Geary.default') loop do packet = @gearman.grab_job case packet when Gearman::Packet::JOB_ASSIGN perform(packet) when Gearman::Packet::NO_JOB @gearman.pre_sleep else break end end end |