Class: Henchman::Worker::Task
- Inherits:
-
Object
- Object
- Henchman::Worker::Task
- Defined in:
- lib/henchman/worker.rb
Overview
The handling of an incoming message.
Instance Attribute Summary collapse
-
#exception ⇒ Object
- Exception
-
any Exception this Task has fallen victim to.
-
#headers ⇒ Object
- AMQP::Header
-
The metadata of the message.
-
#message ⇒ Object
- Object
-
The message itself.
-
#result ⇒ Object
- Object
-
the result of executing this Task.
-
#worker ⇒ Object
- Henchman::Worker
-
the Henchman::Worker this Task belongs to.
Instance Method Summary collapse
-
#call ⇒ Object
Call this Task.
-
#enqueue(queue_name, message) ⇒ Object
Enqueue something on another queue.
-
#initialize(worker, headers, message) ⇒ Task
constructor
Create a Task for a given Henchman::Worker.
-
#queue_name ⇒ String
The name of the queue the worker of this task listens to.
-
#unsubscribe! ⇒ Object
Unsubscribe the Henchman::Worker of this Task from the queue it subscribes to.
Constructor Details
#initialize(worker, headers, message) ⇒ Task
Create a Henchman::Worker::Task for a given Henchman::Worker.
45 46 47 48 49 |
# File 'lib/henchman/worker.rb', line 45 def initialize(worker, headers, ) @worker = worker @headers = headers @message = end |
Instance Attribute Details
#exception ⇒ Object
- Exception
-
any Exception this Henchman::Worker::Task has fallen victim to.
31 32 33 |
# File 'lib/henchman/worker.rb', line 31 def exception @exception end |
#headers ⇒ Object
- AMQP::Header
-
The metadata of the message.
17 18 19 |
# File 'lib/henchman/worker.rb', line 17 def headers @headers end |
#message ⇒ Object
- Object
-
The message itself
21 22 23 |
# File 'lib/henchman/worker.rb', line 21 def @message end |
#result ⇒ Object
- Object
-
the result of executing this Henchman::Worker::Task.
36 37 38 |
# File 'lib/henchman/worker.rb', line 36 def result @result end |
#worker ⇒ Object
- Henchman::Worker
-
the Henchman::Worker this Henchman::Worker::Task belongs to.
26 27 28 |
# File 'lib/henchman/worker.rb', line 26 def worker @worker end |
Instance Method Details
#call ⇒ Object
Call this Henchman::Worker::Task.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/henchman/worker.rb', line 61 def call begin @result = instance_eval(&(worker.block)) rescue Exception => e @exception = e @result = instance_eval(&(Henchman.error_handler)) ensure headers.ack if headers.respond_to?(:ack) end end |
#enqueue(queue_name, message) ⇒ Object
Enqueue something on another queue.
78 79 80 81 82 |
# File 'lib/henchman/worker.rb', line 78 def enqueue(queue_name, ) Fiber.new do Henchman.enqueue(queue_name, ) end.resume end |
#queue_name ⇒ String
Returns the name of the queue the worker of this task listens to.
54 55 56 |
# File 'lib/henchman/worker.rb', line 54 def queue_name worker.queue_name end |
#unsubscribe! ⇒ Object
Unsubscribe the Henchman::Worker of this Henchman::Worker::Task from the queue it subscribes to.
87 88 89 |
# File 'lib/henchman/worker.rb', line 87 def unsubscribe! worker.unsubscribe! end |