Class: Salemove::ProcessHandler::PivotProcess::TapServiceSpawner

Inherits:
Object
  • Object
show all
Defined in:
lib/salemove/process_handler/pivot_process.rb

Instance Method Summary collapse

Constructor Details

#initialize(service, freddy:, logger:, benchmarker:, exception_notifier:) ⇒ TapServiceSpawner

Returns a new instance of TapServiceSpawner.



91
92
93
94
95
96
97
# File 'lib/salemove/process_handler/pivot_process.rb', line 91

def initialize(service, freddy:, logger:, benchmarker:, exception_notifier:)
  @service = service
  @freddy = freddy
  @logger = logger
  @benchmarker = benchmarker
  @exception_notifier = exception_notifier
end

Instance Method Details

#delegate_to_service(input) ⇒ Object



105
106
107
108
109
110
# File 'lib/salemove/process_handler/pivot_process.rb', line 105

def delegate_to_service(input)
  @logger.info 'Received request', input
  @benchmarker.call(input) { @service.call(input) }
rescue StandardError => exception
  handle_exception(exception, input)
end

#handle_exception(exception, input) ⇒ Object



112
113
114
115
116
117
# File 'lib/salemove/process_handler/pivot_process.rb', line 112

def handle_exception(exception, input)
  message = [exception.inspect, *exception.backtrace].join("\n")
  @logger.error(message, input)

  @exception_notifier.notify_or_ignore(exception, input) if @exception_notifier
end

#spawn(queue) ⇒ Object



99
100
101
102
103
# File 'lib/salemove/process_handler/pivot_process.rb', line 99

def spawn(queue)
  @freddy.tap_into(queue) do |input|
    delegate_to_service(input.merge(type: queue))
  end
end