Class: Sidekiq::Instrument::ClientMiddleware

Inherits:
Object
  • Object
show all
Includes:
MetricNames
Defined in:
lib/sidekiq/instrument/middleware/client.rb

Instance Method Summary collapse

Methods included from MetricNames

#max_retries, #metric_name, #worker_dog_options

Instance Method Details

#call(worker_class, job, queue, _redis_pool) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sidekiq/instrument/middleware/client.rb', line 10

def call(worker_class, job, queue, _redis_pool)
  # worker_class is a const in sidekiq >= 6.x
  klass = Object.const_get(worker_class.to_s)
  class_instance = klass.new

  # Depending on the type of perform called, this method can be hit either
  # once or twice for the same Job ID.
  #
  # perform_async:
  #   - once when it is enqueued, with no job['at'] key
  # perform_in:
  #   - once when it is scheduled, with job['at'] key
  #   - once when it is enqueued, without job['at'] key
  if job['at'].present?
    Statter.statsd.increment(metric_name(class_instance, 'schedule'))
    Statter.dogstatsd&.increment('sidekiq.schedule', worker_dog_options(class_instance, job))
  else
    WorkerMetrics.trace_workers_increment_counter(klass.name.underscore)
    Statter.statsd.increment(metric_name(class_instance, 'enqueue'))
    Statter.dogstatsd&.increment('sidekiq.enqueue', worker_dog_options(class_instance, job))
  end

  Statter.dogstatsd&.flush(sync: true)
  yield
end