Class: Optimizely::ForwardingEventProcessor

Inherits:
EventProcessor show all
Defined in:
lib/optimizely/event/forwarding_event_processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(event_dispatcher, logger = nil, notification_center = nil) ⇒ ForwardingEventProcessor

ForwardingEventProcessor is a basic transformation stage for converting the event batch into a LogEvent to be dispatched.



23
24
25
26
27
# File 'lib/optimizely/event/forwarding_event_processor.rb', line 23

def initialize(event_dispatcher, logger = nil, notification_center = nil)
  @event_dispatcher = event_dispatcher
  @logger = logger || NoOpLogger.new
  @notification_center = notification_center
end

Instance Method Details

#process(user_event) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/optimizely/event/forwarding_event_processor.rb', line 29

def process(user_event)
  log_event = Optimizely::EventFactory.create_log_event(user_event, @logger)

  begin
    @event_dispatcher.dispatch_event(log_event)
    @notification_center&.send_notifications(
      NotificationCenter::NOTIFICATION_TYPES[:LOG_EVENT],
      log_event
    )
  rescue StandardError => e
    @logger.log(Logger::ERROR, "Error dispatching event: #{log_event} #{e.message}.")
  end
end