Class: Jackhammer::MessageReceiver

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_classObject (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(message)
  handler = Object.const_get(handler_class)
  if handler.respond_to?(:perform_async)
    handler.perform_async message
  else
    handler.call message
  end
ensure
  ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord::Base)
end