Sha256: 163196912af71fe357c9f1481ec6ca0aaa922f8c1df71ef3b769fae6464538cc

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

require 'toy/instrumentation/subscriber'

module Toy
  module Instrumentation
    class Subscriber
      # Public: Use this as the subscribed block.
      def self.call(name, start, ending, transaction_id, payload)
        new(name, start, ending, transaction_id, payload).update
      end

      # Private: Initializes a new event processing instance.
      def initialize(name, start, ending, transaction_id, payload)
        @name = name
        @start = start
        @ending = ending
        @payload = payload
        @duration = ending - start
        @transaction_id = transaction_id

        @action = @name.split('.').first
        @model = @payload[:model]
      end

      # Public: Actually update all the timers for the event.
      #
      # Returns nothing.
      def update
        update_timer "toystore.#{@action}"
        update_timer "toystore.#{@model}.#{@action}"
      end

      # Internal: Override in subclass.
      def update_timer(metric)
        raise 'not implemented'
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
toystore-0.13.2 lib/toy/instrumentation/subscriber.rb