Module: StandardCircuit::EventEmitter Private

Defined in:
lib/standard_circuit/event_emitter.rb

Overview

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

Internal helper that emits StandardCircuit lifecycle events through whichever event reporter is live in the host process.

  • On Rails 8.1+, ‘Rails.event.notify(name, **payload)` is the canonical bus.

  • On older Rails (or any host without the structured reporter), we fall back to ‘ActiveSupport::Notifications.instrument(name, payload)`.

Detection is performed at *call time* — the gem is required before Rails has finished booting, so we cannot cache the decision at load time.

Class Method Summary collapse

Class Method Details

.emit(event_name, payload) ⇒ 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.

Emit a single event. Both backends are best-effort: any exception raised by a subscriber is swallowed so circuit-breaker observability never takes down a circuit-protected request.



19
20
21
22
23
24
25
26
27
# File 'lib/standard_circuit/event_emitter.rb', line 19

def emit(event_name, payload)
  if rails_event_available?
    ::Rails.event.notify(event_name, **payload)
  else
    ::ActiveSupport::Notifications.instrument(event_name, payload)
  end
rescue => e
  warn "[StandardCircuit] event emit for #{event_name.inspect} failed: #{e.class}: #{e.message}"
end

.rails_event_available?Boolean

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.

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/standard_circuit/event_emitter.rb', line 29

def rails_event_available?
  defined?(::Rails) &&
    ::Rails.respond_to?(:event) &&
    ::Rails.event.respond_to?(:notify)
end