Sha256: 68ad0b4ac429ec12fcb000d9fd3547ddb27943459f3f9e06061e17020dc1951b

Contents?: true

Size: 855 Bytes

Versions: 4

Compression:

Stored size: 855 Bytes

Contents

module Datadog::Notifications::Plugins
  class ActiveJob < Base

    attr_reader :metric_name

    # Options:
    #
    # *<tt>:metric_name</tt> - the metric name, defaults to "activejob.perform"
    # *<tt>:tags</tt>        - additional tags
    def initialize(opts={})
      super
      @metric_name = opts[:metric_name] || "activejob.perform"

      Datadog::Notifications.subscribe 'perform.active_job' do |reporter, event|
        record reporter, event
      end
    end

    private

    def record(reporter, event)
      job  = event.payload[:job]
      name = job.class.name.sub(/Job$/, '').underscore
      tags = self.tags + %W[job:#{name} queue:#{job.queue_name}]

      reporter.batch do
        reporter.increment metric_name, tags: tags
        reporter.timing "#{metric_name}.time", event.duration, tags: tags
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
datadog-notifications-0.5.4 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.5.3 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.5.2 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.5.1 lib/datadog/notifications/plugins/active_job.rb