Class: Jackhammer::MessageReceiver
- Inherits:
-
Object
- Object
- Jackhammer::MessageReceiver
- Defined in:
- lib/jackhammer/message_receiver.rb
Overview
An object meant to be instantiated once but used on each payload received via the #call method
Instance Attribute Summary collapse
-
#handler_class ⇒ Object
readonly
Returns the value of attribute handler_class.
Instance Method Summary collapse
- #call(message) ⇒ Object
-
#initialize(handler_class) ⇒ MessageReceiver
constructor
A new instance of MessageReceiver.
Constructor Details
#initialize(handler_class) ⇒ MessageReceiver
Returns a new instance of MessageReceiver.
7 8 9 |
# File 'lib/jackhammer/message_receiver.rb', line 7 def initialize(handler_class) @handler_class = handler_class end |
Instance Attribute Details
#handler_class ⇒ Object (readonly)
Returns the value of attribute handler_class.
5 6 7 |
# File 'lib/jackhammer/message_receiver.rb', line 5 def handler_class @handler_class end |
Instance Method Details
#call(message) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/jackhammer/message_receiver.rb', line 11 def call() handler = Object.const_get(handler_class) if handler.respond_to?(:perform_async) handler.perform_async else handler.call end ensure ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord::Base) end |