Module: Octo::Helpers::ApiConsumerHelper

Defined in:
lib/octocore-mongo/helpers/api_consumer_helper.rb

Overview

Helper Module for Octo Consumer

Instance Method Summary collapse

Instance Method Details

#call_hooks(event, *args) ⇒ Object

Set Octo callbacks

Parameters:

  • event (String)

    Event name

  • *args (Hash)

    Points to the messsage hash



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

Parameters:

  • msg (Hash)

    Hash Message



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.message
    puts e.backtrace.inspect
  end
end

#valid_eventsSet<Symbol>

Get all the valid events

Returns:

  • (Set<Symbol>)

    Valid events globally



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