Class: DaemonObjects::ConsumerBase
- Inherits:
-
Object
- Object
- DaemonObjects::ConsumerBase
- Includes:
- NewRelic::Agent::Instrumentation::ControllerInstrumentation
- Defined in:
- lib/daemon_objects/consumer_base.rb
Class Attribute Summary collapse
-
.message_handler ⇒ Object
Returns the value of attribute message_handler.
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
Instance Method Summary collapse
- #handle_message(payload) ⇒ Object
-
#initialize(logger) ⇒ ConsumerBase
constructor
A new instance of ConsumerBase.
- #run ⇒ Object
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_handler ⇒ Object
Returns the value of attribute message_handler.
6 7 8 |
# File 'lib/daemon_objects/consumer_base.rb', line 6 def @message_handler end |
Instance Attribute Details
#logger ⇒ Object
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
31 32 33 34 |
# File 'lib/daemon_objects/consumer_base.rb', line 31 def self.(&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 (payload) logger.info("Handling message #{payload}") response = (payload) logger.info("Completed handling message") response rescue StandardError => e logger.error("#{e.class}: #{e.}") logger.error(e.backtrace.join("\n")) Airbrake.notify(e) if defined?(Airbrake) e end |
#run ⇒ Object
15 16 17 |
# File 'lib/daemon_objects/consumer_base.rb', line 15 def run logger.info("Starting consumer") end |