Class: NextStation::Logging::Subscribers::Operation Private

Inherits:
Base
  • Object
show all
Defined in:
lib/next_station/logging/subscribers/operation.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Subscriber for operation lifecycle events.

Constant Summary

Constants inherited from Base

Base::LEVELS

Instance Method Summary collapse

Methods inherited from Base

subscribe

Instance Method Details

#on_start(event) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • event (Dry::Monitor::Event)


18
19
20
21
22
23
# File 'lib/next_station/logging/subscribers/operation.rb', line 18

def on_start(event)
  log_event(event, extra_data: {
    message: "Started operation: #{event[:operation]}",
    event_kind: 'operation.start'
  })
end

#on_stop(event) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • event (Dry::Monitor::Event)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/next_station/logging/subscribers/operation.rb', line 26

def on_stop(event)
  result_status = event[:result].success? ? 'success' : 'failure'
  result_error_type = event[:result].error&.type if event[:result].failure?

  payload = {}
  payload[:duration] = event[:duration]
  payload[:result] = result_status
  payload[:error_type] = result_error_type.to_s if result_error_type

  log_event(event, extra_data: {
    message: "completed operation: #{event[:operation]} with #{result_status}",
    event_kind: 'operation.stop',
    payload: payload
  })
end

#subscribe(monitor) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • monitor (Dry::Monitor::Notifications)


12
13
14
15
# File 'lib/next_station/logging/subscribers/operation.rb', line 12

def subscribe(monitor)
  monitor.subscribe('operation.start') { |event| on_start(event) }
  monitor.subscribe('operation.stop') { |event| on_stop(event) }
end