mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
27 lines
439 B
Ruby
27 lines
439 B
Ruby
module Sidekiq
|
|
class JobLogger
|
|
|
|
def call(item, queue)
|
|
begin
|
|
start = Time.now
|
|
logger.info("start".freeze)
|
|
yield
|
|
logger.info("done: #{elapsed(start)} sec")
|
|
rescue Exception
|
|
logger.info("fail: #{elapsed(start)} sec")
|
|
raise
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def elapsed(start)
|
|
(Time.now - start).round(3)
|
|
end
|
|
|
|
def logger
|
|
Sidekiq.logger
|
|
end
|
|
end
|
|
end
|
|
|