Class: DaemonObjects::ConsumerBase

Inherits:
Object
  • Object
show all
Includes:
NewRelic::Agent::Instrumentation::ControllerInstrumentation
Defined in:
lib/daemon_objects/consumer_base.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ ConsumerBase

Returns a new instance of ConsumerBase.



11
12
13
# File 'lib/daemon_objects/consumer_base.rb', line 11

def initialize(logger)
  @logger = logger
end

Class Attribute Details

.message_handlerObject

Returns the value of attribute message_handler.



6
7
8
# File 'lib/daemon_objects/consumer_base.rb', line 6

def message_handler
  @message_handler
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



9
10
11
# File 'lib/daemon_objects/consumer_base.rb', line 9

def logger
  @logger
end

Class Method Details

.handle_messages_with(&block) ⇒ Object

Raises:

  • (StandardError)


31
32
33
34
# File 'lib/daemon_objects/consumer_base.rb', line 31

def self.handle_messages_with(&block)
  raise StandardError.new("Provided block must take at least one argument - 'payload'") if block.arity < 1
  define_method(:handle_message_impl, &block) 
end

Instance Method Details

#handle_message(payload) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/daemon_objects/consumer_base.rb', line 19

def handle_message(payload)
  logger.info("Handling message #{payload}")
  response = handle_message_impl(payload)
  logger.info("Completed handling message")
  response
rescue StandardError => e
  logger.error("#{e.class}:  #{e.message}")
  logger.error(e.backtrace.join("\n"))
  Airbrake.notify(e) if defined?(Airbrake)
  e
end

#runObject



15
16
17
# File 'lib/daemon_objects/consumer_base.rb', line 15

def run
  logger.info("Starting consumer")
end