Sha256: ca1aa2989341ff7a5a0a39b898234db92a58ca52650637dd46a32c41abad56bf

Contents?: true

Size: 892 Bytes

Versions: 4

Compression:

Stored size: 892 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(metric_name: 'activejob.perform', **opts)
      super

      @metric_name = metric_name
      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
      queue = job.queue_name.tr(':', '_')
      tags  = self.tags + %W[job:#{name} queue:#{queue}]

      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.7.2 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.7.1 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.7.0 lib/datadog/notifications/plugins/active_job.rb
datadog-notifications-0.6.7 lib/datadog/notifications/plugins/active_job.rb