Sha256: 1f4ed3f1d4ccb40668087885ebb0245a724a4ce31f6e9ccc4ac0987b45ab5b1b

Contents?: true

Size: 1.51 KB

Versions: 36

Compression:

Stored size: 1.51 KB

Contents

module Appsignal
  class Subscriber
    attr_reader :as_subscriber

    def initialize
      subscribe
    end

    def subscribe
      Appsignal.logger.debug('Subscribing to notifications')
      # Subscribe to notifications that don't start with a !
      @as_subscriber = ActiveSupport::Notifications.subscribe(/^[^!]/, self)
    end

    def unsubscribe
      if @as_subscriber
        Appsignal.logger.debug('Unsubscribing from notifications')
        ActiveSupport::Notifications.unsubscribe(@as_subscriber)
        @as_subscriber = nil
      end
    end

    def resubscribe
      Appsignal.logger.debug('Resubscribing to notifications')
      unsubscribe
      subscribe
    end

    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

    def start(name, id, payload)
      return unless transaction = Appsignal::Transaction.current
      return if transaction.nil_transaction? || transaction.paused?

      transaction.start_event
    end

    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
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
appsignal-1.3.6 lib/appsignal/subscriber.rb
appsignal-1.3.6.beta.1 lib/appsignal/subscriber.rb
appsignal-1.3.5 lib/appsignal/subscriber.rb
appsignal-1.3.5.beta.1 lib/appsignal/subscriber.rb
appsignal-1.3.4 lib/appsignal/subscriber.rb
appsignal-1.3.3 lib/appsignal/subscriber.rb
appsignal-1.4.0.alpha.2 lib/appsignal/subscriber.rb
appsignal-1.4.0.alpha.1 lib/appsignal/subscriber.rb
appsignal-1.3.2 lib/appsignal/subscriber.rb
appsignal-1.3.1 lib/appsignal/subscriber.rb
appsignal-1.3.0 lib/appsignal/subscriber.rb
appsignal-1.3.0.beta.3 lib/appsignal/subscriber.rb
appsignal-1.3.0.beta.2 lib/appsignal/subscriber.rb
appsignal-1.3.0.beta.1 lib/appsignal/subscriber.rb
appsignal-1.2.5 lib/appsignal/subscriber.rb
appsignal-1.2.4 lib/appsignal/subscriber.rb
appsignal-1.2.4.beta.4 lib/appsignal/subscriber.rb
appsignal-1.2.4.beta.3 lib/appsignal/subscriber.rb
appsignal-1.2.4.beta.2 lib/appsignal/subscriber.rb
appsignal-1.2.4.beta.1 lib/appsignal/subscriber.rb