Class: Gitlab::Metrics::SidekiqMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/metrics/sidekiq_middleware.rb

Overview

Sidekiq middleware for tracking jobs.

This middleware is intended to be used as a server-side middleware.

Instance Method Summary collapse

Instance Method Details

#call(worker, payload, queue) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gitlab/metrics/sidekiq_middleware.rb', line 9

def call(worker, payload, queue)
  trans = BackgroundTransaction.new(worker.class)

  begin
    # Old gitlad-shell messages don't provide enqueued_at/created_at attributes
    enqueued_at = payload['enqueued_at'] || payload['created_at'] || 0
    trans.set(:gitlab_transaction_sidekiq_queue_duration_total, Time.current.to_f - enqueued_at) do
      multiprocess_mode :livesum
    end
    trans.run { yield }
  rescue Exception => error # rubocop: disable Lint/RescueException
    trans.add_event(:sidekiq_exception)

    raise error
  ensure
    add_info_to_payload(payload, trans)
  end
end