Module: Octo::Helpers::ApiConsumerHelper
- Defined in:
- lib/octocore-mongo/helpers/api_consumer_helper.rb
Overview
Helper Module for Octo Consumer
Instance Method Summary collapse
-
#call_hooks(event, *args) ⇒ Object
Set Octo callbacks.
-
#handle(msg) ⇒ Object
Handles Kafka messages and perform required operations.
-
#valid_events ⇒ Set<Symbol>
Get all the valid events.
Instance Method Details
#call_hooks(event, *args) ⇒ Object
Set Octo callbacks
43 44 45 46 |
# File 'lib/octocore-mongo/helpers/api_consumer_helper.rb', line 43 def call_hooks(event, *args) hook = [:after, event.gsub('.', '_')].join('_').to_sym Octo::Callbacks.run_hook(hook, *args) end |
#handle(msg) ⇒ Object
Handles Kafka messages and perform required operations
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/octocore-mongo/helpers/api_consumer_helper.rb', line 26 def handle(msg) msg_obj = Octo::Message::Message.new(msg) msg = msg_obj.to_h begin eventName = msg[:event_name] if (valid_events.include?eventName) call_hooks(eventName, msg) end rescue Exception => e puts e. puts e.backtrace.inspect end end |
#valid_events ⇒ Set<Symbol>
Get all the valid events
12 13 14 |
# File 'lib/octocore-mongo/helpers/api_consumer_helper.rb', line 12 def valid_events Set.new(Octo.get_config(:allowed_events)) end |