Class: StandardCircuit::Subscribers Private
- Inherits:
-
Object
- Object
- StandardCircuit::Subscribers
- Defined in:
- lib/standard_circuit/subscribers.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.
Registers internal and user-supplied subscribers against whichever event bus is live (Rails.event on 8.1+, ActiveSupport::Notifications elsewhere).
Each subscriber must respond to ‘call(event_name, payload)`. Internal subscribers (Logger / Sentry / Metrics) are built from the live config so changes to `metric_prefix` / `logger` propagate when `setup!` is re-run.
Subscriptions cover the namespace prefix ‘standard_circuit.`, so a single registration on each backend listens for every lifecycle event the gem emits — bridge color transitions plus runner-side fallback / registration.
Defined Under Namespace
Classes: RailsEventAdapter
Constant Summary collapse
- EVENT_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"standard_circuit."- EVENT_REGEXP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/\A#{Regexp.escape(EVENT_PATTERN)}/
Instance Method Summary collapse
-
#initialize ⇒ Subscribers
constructor
private
A new instance of Subscribers.
- #setup! ⇒ Object private
-
#teardown! ⇒ Object
private
Tear down both backends.
Constructor Details
#initialize ⇒ Subscribers
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 a new instance of Subscribers.
18 19 20 21 |
# File 'lib/standard_circuit/subscribers.rb', line 18 def initialize @rails_event_subscribers = [] @as_subscribers = [] end |
Instance Method Details
#setup! ⇒ 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.
23 24 25 26 |
# File 'lib/standard_circuit/subscribers.rb', line 23 def setup! teardown! register(internal_subscribers + extra_subscribers) end |
#teardown! ⇒ 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.
Tear down both backends. Rails.event subscribers are unsubscribed unconditionally — we recorded them at registration time, so we must remove them even if Rails.event has since become unavailable (e.g. test ‘hide_const(“Rails”)`). Otherwise the wrappers would remain live in the bus while we believe they are gone.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/standard_circuit/subscribers.rb', line 33 def teardown! @rails_event_subscribers.each do |subscriber| ::Rails.event.unsubscribe(subscriber) if EventEmitter.rails_event_available? rescue StandardError # If Rails.event is gone (test isolation), we can do nothing more — # clearing the array still releases our reference. end @rails_event_subscribers.clear @as_subscribers.each do |subscriber| ::ActiveSupport::Notifications.unsubscribe(subscriber) end @as_subscribers.clear end |