2018-03-15 12:00:53 -04:00
|
|
|
# frozen_string_literal: true
|
2017-01-17 17:58:08 -05:00
|
|
|
module Sidekiq
|
|
|
|
class JobLogger
|
|
|
|
|
|
|
|
def call(item, queue)
|
2018-10-18 16:51:58 -04:00
|
|
|
start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
2018-02-16 16:11:54 -05:00
|
|
|
logger.info("start")
|
2017-05-08 15:50:36 -04:00
|
|
|
yield
|
|
|
|
logger.info("done: #{elapsed(start)} sec")
|
|
|
|
rescue Exception
|
|
|
|
logger.info("fail: #{elapsed(start)} sec")
|
|
|
|
raise
|
2017-01-17 17:58:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def elapsed(start)
|
2018-10-18 16:51:58 -04:00
|
|
|
(::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start).round(3)
|
2017-01-17 17:58:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def logger
|
|
|
|
Sidekiq.logger
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|