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
-
#app_directory ⇒ Object
readonly
Returns the value of attribute app_directory.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Class Method Summary collapse
Instance Method Summary collapse
- #handle_message(payload) ⇒ Object
-
#initialize(opts) ⇒ ConsumerBase
constructor
A new instance of ConsumerBase.
- #run ⇒ Object
Constructor Details
#initialize(opts) ⇒ ConsumerBase
Returns a new instance of ConsumerBase.
11 12 13 14 15 |
# File 'lib/daemon_objects/consumer_base.rb', line 11 def initialize(opts) @logger = opts[:logger] @app_directory = opts[:app_directory] @environment = opts[:environment] 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
#app_directory ⇒ Object (readonly)
Returns the value of attribute app_directory.
9 10 11 |
# File 'lib/daemon_objects/consumer_base.rb', line 9 def app_directory @app_directory end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
9 10 11 |
# File 'lib/daemon_objects/consumer_base.rb', line 9 def environment @environment end |
#logger ⇒ Object (readonly)
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
33 34 35 36 |
# File 'lib/daemon_objects/consumer_base.rb', line 33 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
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/daemon_objects/consumer_base.rb', line 21 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
17 18 19 |
# File 'lib/daemon_objects/consumer_base.rb', line 17 def run logger.info("Starting consumer") end |