Class: SolidObserver::Subscriber

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

Overview

Subscribes to ActiveSupport::Notifications for ActiveJob events.

Monitors job lifecycle events (enqueue, perform, retry_stopped, discard) and records them through the event buffer for observability.

Examples:

Subscribe to job events

SolidObserver::Subscriber.subscribe!

Constant Summary collapse

EVENTS =
%w[
  enqueue.active_job
  perform.active_job
  retry_stopped.active_job
  discard.active_job
].freeze

Class Method Summary collapse

Class Method Details

.subscribe!Object



20
21
22
23
24
# File 'lib/solid_observer/subscriber.rb', line 20

def subscribe!
  return unless subscription_allowed?

  @subscriptions = subscriptions_for_events.compact
end

.subscribed?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/solid_observer/subscriber.rb', line 35

def subscribed?
  !!@subscriptions&.any?
end

.unsubscribe!Object



26
27
28
29
30
31
32
33
# File 'lib/solid_observer/subscriber.rb', line 26

def unsubscribe!
  return unless @subscriptions

  @subscriptions.each do |subscription|
    ActiveSupport::Notifications.unsubscribe(subscription)
  end
  @subscriptions = []
end