Class: SolidObserver::Services::RecordEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_observer/services/record_event.rb

Overview

Records ActiveJob events to the buffer with sampling support.

Extracts job metadata, applies sampling rate, and pushes events to the buffer for batch insertion.

Examples:

Record a job completion

RecordEvent.call(
  event: event,
  event_type: "job_completed",
  buffer: QueueEventBuffer.instance,
  metric_name: "jobs_completed"
)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event, event_type, buffer, metric_name) ⇒ RecordEvent

Returns a new instance of RecordEvent.



27
28
29
30
31
32
# File 'lib/solid_observer/services/record_event.rb', line 27

def initialize(event, event_type, buffer, metric_name)
  @event = event
  @event_type = event_type
  @buffer = buffer
  @metric_name = metric_name
end

Class Method Details

.call(event:, event_type:, buffer:, metric_name:) ⇒ void

This method returns an undefined value.

Parameters:

  • event (ActiveSupport::Notifications::Event)

    The notification event

  • event_type (String)

    Type of event (e.g., “job_enqueued”)

  • buffer (QueueEventBuffer)

    Buffer to push event data to

  • metric_name (String)

    Metric name for incrementing



23
24
25
# File 'lib/solid_observer/services/record_event.rb', line 23

def self.call(event:, event_type:, buffer:, metric_name:)
  new(event, event_type, buffer, metric_name).call
end

Instance Method Details

#callObject



34
35
36
37
38
39
40
41
# File 'lib/solid_observer/services/record_event.rb', line 34

def call
  return unless should_record?

  @buffer.push(build_event_data)
  increment_metric
rescue => e
  handle_error(e)
end