Sha256: 63aafd9d0043090ebc953615387e52c542c6b68b196f5c75336c46d9790db792

Contents?: true

Size: 858 Bytes

Versions: 12

Compression:

Stored size: 858 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|name:#{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

12 entries across 12 versions & 1 rubygems

Version Path
datadog-notifications-0.4.9 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.4.8 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.4.7 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.4.6 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.4.5 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.4.4 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.4.3 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.4.2 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.4.1 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.4.0 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.3.1 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.3.0 lib/datadog/notifications/plugins/active_job.rb