Class: RailsPerformance::Gems::SidekiqExt

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_performance/gems/sidekiq_ext.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ SidekiqExt

Returns a new instance of SidekiqExt.



5
6
# File 'lib/rails_performance/gems/sidekiq_ext.rb', line 5

def initialize(options=nil)
end

Instance Method Details

#call(worker, msg, queue) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rails_performance/gems/sidekiq_ext.rb', line 8

def call(worker, msg, queue)
  now    = Time.current
  record = RailsPerformance::Models::SidekiqRecord.new(
    enqueued_ati: msg['enqueued_at'].to_i,
    datetimei: msg['created_at'].to_i,
    jid: msg['jid'],
    queue: queue,
    start_timei: now.to_i,
    datetime: now.strftime(RailsPerformance::FORMAT),
    worker: msg['wrapped'.freeze] || worker.class.to_s
  )
  begin
    result = yield
    record.status = "success"
    result
  rescue Exception => ex
    record.status   = "exception"
    record.message  = ex.message
    raise ex
  ensure
    # store in ms instead of seconds
    record.duration = (Time.current - now) * 1000
    record.save
    result
  end
end