Class: Loga::Sidekiq6::JobLogger

Inherits:
Sidekiq::JobLogger
  • Object
show all
Defined in:
lib/loga/sidekiq6/job_logger.rb

Constant Summary collapse

EVENT_TYPE =
'sidekiq'.freeze

Instance Method Summary collapse

Instance Method Details

#call(item, _queue) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/loga/sidekiq6/job_logger.rb', line 8

def call(item, _queue)
  start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)

  yield

  ::Sidekiq::Context.current[:elapsed] = elapsed(start)

  loga_log(message: "#{item['class']} with jid: '#{item['jid']}' done", item: item)
rescue Exception => e # rubocop:disable Lint/RescueException
  ::Sidekiq::Context.current[:elapsed] = elapsed(start)

  loga_log(
    message: "#{item['class']} with jid: '#{item['jid']}' fail", item: item,
    exception: e
  )

  raise
end

#prepare(job_hash, &block) ⇒ Object



27
28
29
30
31
32
# File 'lib/loga/sidekiq6/job_logger.rb', line 27

def prepare(job_hash, &block)
  super
ensure
  # For sidekiq version < 6.4
  Thread.current[:sidekiq_context] = nil
end