Class: PrometheusExporter::Instrumentation::Sidekiq

Inherits:
Object
  • Object
show all
Defined in:
lib/prometheus_exporter/instrumentation/sidekiq.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: nil) ⇒ Sidekiq

Returns a new instance of Sidekiq.



19
20
21
# File 'lib/prometheus_exporter/instrumentation/sidekiq.rb', line 19

def initialize(client: nil)
  @client = client || PrometheusExporter::Client.default
end

Class Method Details

.death_handlerObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/prometheus_exporter/instrumentation/sidekiq.rb', line 5

def self.death_handler
  -> (job, ex) do
    job_is_fire_and_forget = job["retry"] == false

    unless job_is_fire_and_forget
      PrometheusExporter::Client.default.send_json(
        type: "sidekiq",
        name: job["class"],
        dead: true,
      )
    end
  end
end

Instance Method Details

#call(worker, msg, queue) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/prometheus_exporter/instrumentation/sidekiq.rb', line 23

def call(worker, msg, queue)
  success = false
  shutdown = false
  start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
  result = yield
  success = true
  result
rescue ::Sidekiq::Shutdown => e
  shutdown = true
  raise e
ensure
  duration = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start
  class_name = worker.class.to_s == 'ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper' ?
                 msg['wrapped'] : worker.class.to_s
  @client.send_json(
    type: "sidekiq",
    name: class_name,
    success: success,
    shutdown: shutdown,
    duration: duration
  )
end