Class: Leveret::ResultHandler

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/leveret/result_handler.rb

Overview

Handles the acknowledgement or rejection of messages after execution

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming_message) ⇒ ResultHandler

Returns a new instance of ResultHandler.

Parameters:

  • incoming_message (Message)

    Contains delivery information such as the delivery_tag



11
12
13
# File 'lib/leveret/result_handler.rb', line 11

def initialize(incoming_message)
  self.incoming_message = incoming_message
end

Instance Attribute Details

#incoming_messageObject

Returns the value of attribute incoming_message.



6
7
8
# File 'lib/leveret/result_handler.rb', line 6

def incoming_message
  @incoming_message
end

Instance Method Details

#delayObject

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(incoming_message)
end

#handle(result) ⇒ Object

Call the appropriate handling method for the result

Parameters:

  • result (Symbol)

    Result returned from running the job, one of :success, :reject or :requeue



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

#rejectObject

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

#requeueObject

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

#successObject

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