Class: Appsignal::Subscriber
- Inherits:
-
Object
- Object
- Appsignal::Subscriber
- Defined in:
- lib/appsignal/subscriber.rb
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.
5 6 7 |
# File 'lib/appsignal/subscriber.rb', line 5 def initialize subscribe end |
Instance Attribute Details
#as_subscriber ⇒ Object (readonly)
Returns the value of attribute as_subscriber.
3 4 5 |
# File 'lib/appsignal/subscriber.rb', line 3 def as_subscriber @as_subscriber end |
Instance Method Details
#finish(name, id, payload) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/appsignal/subscriber.rb', line 42 def finish(name, id, payload) return unless transaction = Appsignal::Transaction.current return if transaction.nil_transaction? || transaction.paused? title, body, body_format = Appsignal::EventFormatter.format(name, payload) transaction.finish_event( name, title, body, body_format ) end |
#publish(name, *args) ⇒ Object
29 30 31 32 33 |
# File 'lib/appsignal/subscriber.rb', line 29 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
23 24 25 26 27 |
# File 'lib/appsignal/subscriber.rb', line 23 def resubscribe Appsignal.logger.debug('Resubscribing to notifications') unsubscribe subscribe end |
#start(name, id, payload) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/appsignal/subscriber.rb', line 35 def start(name, id, payload) return unless transaction = Appsignal::Transaction.current return if transaction.nil_transaction? || transaction.paused? transaction.start_event end |
#subscribe ⇒ Object
9 10 11 12 13 |
# File 'lib/appsignal/subscriber.rb', line 9 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
15 16 17 18 19 20 21 |
# File 'lib/appsignal/subscriber.rb', line 15 def unsubscribe if @as_subscriber Appsignal.logger.debug('Unsubscribing from notifications') ActiveSupport::Notifications.unsubscribe(@as_subscriber) @as_subscriber = nil end end |