Class: Leveret::ResultHandler
- Inherits:
-
Object
- Object
- Leveret::ResultHandler
- Extended by:
- Forwardable
- Defined in:
- lib/leveret/result_handler.rb
Overview
Handles the acknowledgement or rejection of messages after execution
Instance Attribute Summary collapse
-
#incoming_message ⇒ Object
Returns the value of attribute incoming_message.
Instance Method Summary collapse
-
#delay ⇒ Object
Acknowledge the message, but publish it onto the delay queue for execution later.
-
#handle(result) ⇒ Object
Call the appropriate handling method for the result.
-
#initialize(incoming_message) ⇒ ResultHandler
constructor
A new instance of ResultHandler.
-
#reject ⇒ Object
Mark the message as rejected (failure).
-
#requeue ⇒ Object
Reject the message and reinsert it onto it’s queue.
-
#success ⇒ Object
Mark the message as acknowledged.
Constructor Details
#initialize(incoming_message) ⇒ ResultHandler
Returns a new instance of ResultHandler.
11 12 13 |
# File 'lib/leveret/result_handler.rb', line 11 def initialize() self. = end |
Instance Attribute Details
#incoming_message ⇒ Object
Returns the value of attribute incoming_message.
6 7 8 |
# File 'lib/leveret/result_handler.rb', line 6 def @incoming_message end |
Instance Method Details
#delay ⇒ Object
Acknowledge the message, but publish it onto the delay queue for execution later
42 43 44 45 46 |
# File 'lib/leveret/result_handler.rb', line 42 def delay log.debug ["[#{delivery_tag}] Delaying message"] channel.acknowledge(delivery_tag) delay_queue.republish() end |
#handle(result) ⇒ Object
Call the appropriate handling method for the result
18 19 20 21 |
# File 'lib/leveret/result_handler.rb', line 18 def handle(result) log.info "[#{delivery_tag}] Job returned #{result}" send(result) if [:success, :reject, :requeue, :delay].include?(result) end |
#reject ⇒ Object
Mark the message as rejected (failure)
30 31 32 33 |
# File 'lib/leveret/result_handler.rb', line 30 def reject log.debug "[#{delivery_tag}] Rejecting message" channel.reject(delivery_tag) end |
#requeue ⇒ Object
Reject the message and reinsert it onto it’s queue
36 37 38 39 |
# File 'lib/leveret/result_handler.rb', line 36 def requeue log.debug "[#{delivery_tag}] Requeueing message" channel.reject(delivery_tag, true) end |
#success ⇒ Object
Mark the message as acknowledged
24 25 26 27 |
# File 'lib/leveret/result_handler.rb', line 24 def success log.debug "[#{delivery_tag}] Acknowledging message" channel.acknowledge(delivery_tag) end |