Class: Appsignal::Subscriber
- Inherits:
-
Object
- Object
- Appsignal::Subscriber
- Defined in:
- lib/appsignal/subscriber.rb
Constant Summary collapse
- BLANK =
''.freeze
Instance Attribute Summary collapse
-
#as_subscriber ⇒ Object
readonly
Returns the value of attribute as_subscriber.
Instance Method Summary collapse
- #finish(name, id, payload) ⇒ Object
-
#initialize ⇒ Subscriber
constructor
A new instance of Subscriber.
- #publish(name, *args) ⇒ Object
- #resubscribe ⇒ Object
- #start(name, id, payload) ⇒ Object
- #subscribe ⇒ Object
- #unsubscribe ⇒ Object
Constructor Details
#initialize ⇒ Subscriber
Returns a new instance of Subscriber.
7 8 9 |
# File 'lib/appsignal/subscriber.rb', line 7 def initialize subscribe end |
Instance Attribute Details
#as_subscriber ⇒ Object (readonly)
Returns the value of attribute as_subscriber.
5 6 7 |
# File 'lib/appsignal/subscriber.rb', line 5 def as_subscriber @as_subscriber end |
Instance Method Details
#finish(name, id, payload) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/appsignal/subscriber.rb', line 44 def finish(name, id, payload) return unless transaction = Appsignal::Transaction.current return if transaction.nil_transaction? || transaction.paused? title, body = Appsignal::EventFormatter.format(name, payload) Appsignal::Extension.finish_event( transaction.transaction_index, name, title || BLANK, body || BLANK ) end |
#publish(name, *args) ⇒ Object
31 32 33 34 35 |
# File 'lib/appsignal/subscriber.rb', line 31 def publish(name, *args) # Not used, it's part of AS notifications but is not used in Rails # and it seems to be unclear what it's function is. See: # https://github.com/rails/rails/blob/master/activesupport/lib/active_support/notifications/fanout.rb#L49 end |
#resubscribe ⇒ Object
25 26 27 28 29 |
# File 'lib/appsignal/subscriber.rb', line 25 def resubscribe Appsignal.logger.debug('Resubscribing to notifications') unsubscribe subscribe end |
#start(name, id, payload) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/appsignal/subscriber.rb', line 37 def start(name, id, payload) return unless transaction = Appsignal::Transaction.current return if transaction.nil_transaction? || transaction.paused? Appsignal::Extension.start_event(transaction.transaction_index) end |
#subscribe ⇒ Object
11 12 13 14 15 |
# File 'lib/appsignal/subscriber.rb', line 11 def subscribe Appsignal.logger.debug('Subscribing to notifications') # Subscribe to notifications that don't start with a ! @as_subscriber = ActiveSupport::Notifications.subscribe(/^[^!]/, self) end |
#unsubscribe ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/appsignal/subscriber.rb', line 17 def unsubscribe if @as_subscriber Appsignal.logger.debug('Unsubscribing from notifications') ActiveSupport::Notifications.unsubscribe(@as_subscriber) @as_subscriber = nil end end |