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.



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

def initialize(options = nil)
end

Instance Method Details

#call(worker, msg, queue) ⇒ Object



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

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 # rubocop:disable Lint/RescueException
    record.status = "exception"
    record.message = ex.message
    raise ex
  ensure
    # store in ms instead of seconds
    record.duration = (Time.current - now) * 1000
    record.save
  end
end