Class: OmniEvent::ProcessDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/omni_event/process_dispatcher.rb

Overview

Finds the registered processor for a given WebhookEvent and runs it.

Register processors in your initializer:

OmniEvent.configure do |config|
config.processors = {
  "Siscomex" => SiscomexProcessor,
  "DHL"      => DHLProcessor
}
end

Class Method Summary collapse

Class Method Details

.call(event) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/omni_event/process_dispatcher.rb', line 16

def self.call(event)
  processor_class = resolve(event)

  unless processor_class
    Rails.logger.warn "[OmniEvent] No processor registered for notifier '#{event.webhook_notifier.name}'. Marking as processed."
    event.update!(status: :processed)
    return
  end

  processor_class.new(event).process!
  event.update!(status: :processed)
rescue => e
  event.update!(status: :failed)
  raise e
end