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, messenger, exception_notifier) ⇒ TapServiceSpawner

Returns a new instance of TapServiceSpawner.



89
90
91
92
93
# File 'lib/salemove/process_handler/pivot_process.rb', line 89

def initialize(service, messenger, exception_notifier)
  @service = service
  @messenger = messenger
  @exception_notifier = exception_notifier
end

Instance Method Details

#delegate_to_service(input) ⇒ Object



102
103
104
105
106
107
# File 'lib/salemove/process_handler/pivot_process.rb', line 102

def delegate_to_service(input)
  PivotProcess.logger.info "Received request", input
  PivotProcess.benchmark(input) { @service.call(input) }
rescue => exception
  handle_exception(exception, input)
end

#handle_exception(e, input) ⇒ Object



109
110
111
112
113
114
# File 'lib/salemove/process_handler/pivot_process.rb', line 109

def handle_exception(e, input)
  PivotProcess.logger.error(e.inspect + "\n" + e.backtrace.join("\n"), request_id: input[:request_id])
  if @exception_notifier
    @exception_notifier.notify_or_ignore(e, cgi_data: ENV.to_hash, parameters: input)
  end
end

#spawn(queue) ⇒ Object



95
96
97
98
99
100
# File 'lib/salemove/process_handler/pivot_process.rb', line 95

def spawn(queue)
  @messenger.tap_into(queue) do |input|
    request_id = SecureRandom.hex(5)
    delegate_to_service(input.merge(type: queue, request_id: request_id))
  end
end