Class: Proletariat::ExceptionHandler

Inherits:
Actor
  • Object
show all
Includes:
Concerns::Logging
Defined in:
lib/proletariat/exception_handler.rb

Overview

Public: Handles messages whose work raised an exception. Should overwrite

the #work method to implement retry/drop logic.

Direct Known Subclasses

Drop, ExponentialBackoff

Instance Method Summary collapse

Methods included from Concerns::Logging

#log_info

Methods inherited from Actor

#on_message

Methods included from ActorCommon

included, #on_event

Constructor Details

#initialize(queue_name) ⇒ ExceptionHandler

Returns a new instance of ExceptionHandler.



9
10
11
12
# File 'lib/proletariat/exception_handler.rb', line 9

def initialize(queue_name)
  @queue_name = queue_name
  setup
end

Instance Method Details

#actor_work(message) ⇒ Object

Internal: Handles the Actor mailbox. Delegates work to #work.

message - A Message to send.



17
18
19
# File 'lib/proletariat/exception_handler.rb', line 17

def actor_work(message)
  work message.body, message.to, message.headers if message.is_a?(Message)
end

#setupObject

Public: Callback hook for initialization.



22
23
# File 'lib/proletariat/exception_handler.rb', line 22

def setup
end

#work(body, to, headers) ⇒ Object

Public: Handles an incoming message to perform background work.

body - The failed message body. to - The failed message’s routing key. headers - The failed message’s headers.

Raises NotImplementedError unless implemented in subclass.



32
33
34
# File 'lib/proletariat/exception_handler.rb', line 32

def work(body, to, headers)
  fail NotImplementedError
end

#work_methodObject

Public: Use #actor_work to handle the actor mailbox.



37
38
39
# File 'lib/proletariat/exception_handler.rb', line 37

def work_method
  :actor_work
end