Class: Chronos::Rails::NotificationsSubscriber
- Inherits:
-
Object
- Object
- Chronos::Rails::NotificationsSubscriber
- Defined in:
- lib/chronos/rails/notifications_subscriber.rb
Overview
Converts public ActiveSupport notifications into bounded Chronos telemetry.
Constant Summary collapse
- EVENTS =
%w( process_action.action_controller render_template.action_view sql.active_record deliver.action_mailer perform.active_job cache_read.active_support cache_write.active_support cache_fetch_hit.active_support ).freeze
Class Attribute Summary collapse
-
.installed_buses ⇒ Object
readonly
Returns the value of attribute installed_buses.
-
.mutex ⇒ Object
readonly
Returns the value of attribute mutex.
Instance Method Summary collapse
- #handle(name, arguments) ⇒ Object
-
#initialize(notifier = Chronos, notifications = nil) ⇒ NotificationsSubscriber
constructor
A new instance of NotificationsSubscriber.
- #install ⇒ Object
Constructor Details
#initialize(notifier = Chronos, notifications = nil) ⇒ NotificationsSubscriber
Returns a new instance of NotificationsSubscriber.
29 30 31 32 |
# File 'lib/chronos/rails/notifications_subscriber.rb', line 29 def initialize(notifier = Chronos, notifications = nil) @notifier = notifier @notifications = notifications || active_support_notifications end |
Class Attribute Details
.installed_buses ⇒ Object (readonly)
Returns the value of attribute installed_buses.
26 27 28 |
# File 'lib/chronos/rails/notifications_subscriber.rb', line 26 def installed_buses @installed_buses end |
.mutex ⇒ Object (readonly)
Returns the value of attribute mutex.
26 27 28 |
# File 'lib/chronos/rails/notifications_subscriber.rb', line 26 def mutex @mutex end |
Instance Method Details
#handle(name, arguments) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/chronos/rails/notifications_subscriber.rb', line 48 def handle(name, arguments) event = notification_event(name, arguments) dispatch(name, event[:payload], event[:duration_ms]) rescue StandardError false end |
#install ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/chronos/rails/notifications_subscriber.rb', line 34 def install return false unless @notifications && @notifications.respond_to?(:subscribe) self.class.mutex.synchronize do return false if self.class.installed_buses[@notifications.object_id] event_names.each { |name| subscribe(name) } self.class.installed_buses[@notifications.object_id] = true end true rescue StandardError false end |