class Sapience::Extensions::ActiveJob::Notifications

Public Class Methods

new(opts = {}) click to toggle source

Options:

*:metric_name - the metric name, defaults to “activejob.perform” *:tags - additional tags

# File lib/sapience/extensions/active_job/notifications.rb, line 11
def initialize(opts = {})
  super
  @metric_name = opts[:metric_name] || "activejob.perform"

  Sapience::Extensions::Notifications.subscribe "perform.active_job" do |event|
    record event
  end
end

Private Instance Methods

record(event) click to toggle source
# File lib/sapience/extensions/active_job/notifications.rb, line 22
def record(event) # rubocop:disable AbcSize
  return unless record?

  job  = event.payload[:job]
  name = job.class.name.sub(/Job$/, "").underscore
  tags = self.tags + %W(name:#{name} queue:#{job.queue_name})
  metrics.batch do
    metrics.increment metric_name, tags: tags
    metrics.timing "#{metric_name}.time", event.duration, tags: tags
  end
end