1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00
mperham--sidekiq/lib/sidekiq/job_logger.rb

26 lines
511 B
Ruby
Raw Normal View History

# frozen_string_literal: true
module Sidekiq
class JobLogger
def call(item, queue)
start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
2018-02-16 16:11:54 -05:00
logger.info("start")
yield
logger.info("done: #{elapsed(start)} sec")
rescue Exception
logger.info("fail: #{elapsed(start)} sec")
raise
end
private
def elapsed(start)
(::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start).round(3)
end
def logger
Sidekiq.logger
end
end
end