Sha256: 8c66655e0d7305ed6be928cb92296a834a39f8d9385b664edea1527deebba5ac

Contents?: true

Size: 1.19 KB

Versions: 9

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module PrometheusExporter::Instrumentation
  class Sidekiq
    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

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

    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
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
prometheus_exporter-0.5.3 lib/prometheus_exporter/instrumentation/sidekiq.rb
prometheus_exporter-0.5.2 lib/prometheus_exporter/instrumentation/sidekiq.rb
prometheus_exporter-0.5.1 lib/prometheus_exporter/instrumentation/sidekiq.rb
prometheus_exporter-0.5.0 lib/prometheus_exporter/instrumentation/sidekiq.rb
prometheus_exporter-0.4.17 lib/prometheus_exporter/instrumentation/sidekiq.rb
prometheus_exporter-0.4.16 lib/prometheus_exporter/instrumentation/sidekiq.rb
prometheus_exporter-0.4.15 lib/prometheus_exporter/instrumentation/sidekiq.rb
prometheus_exporter-0.4.14 lib/prometheus_exporter/instrumentation/sidekiq.rb
prometheus_exporter-0.4.13 lib/prometheus_exporter/instrumentation/sidekiq.rb