Class: SidekiqJobStats::Middleware

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Component
Defined in:
lib/sidekiq_job_stats/middleware.rb

Instance Method Summary collapse

Instance Method Details

#call(_worker, msg, queue) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sidekiq_job_stats/middleware.rb', line 10

def call(_worker, msg, queue)
  data = {
    enqueued_at: msg['enqueued_at'], started_at: Time.now, payload: msg['args'], status: 'success',
    exception: '', queue: queue
  }

  begin
    yield
  rescue StandardError => e
    data[:status] = 'failed'
    data[:exception] = e.message
    raise e
  ensure
    data[:finished_at] = Time.now
    data[:duration] = data[:finished_at] - data[:started_at]
    push_stats(data, msg['class'])
  end
end