2012-02-25 16:43:53 -05:00
|
|
|
module Sidekiq
|
|
|
|
module Middleware
|
|
|
|
module Server
|
|
|
|
class Logging
|
2012-05-12 17:00:42 -04:00
|
|
|
|
2012-10-18 14:31:36 -04:00
|
|
|
def call(worker, item, queue)
|
2012-11-03 14:47:48 -04:00
|
|
|
Sidekiq::Logging.with_context("#{worker.class.to_s} JID-#{item['jid']}") do
|
2012-05-15 22:44:35 -04:00
|
|
|
begin
|
|
|
|
start = Time.now
|
|
|
|
logger.info { "start" }
|
|
|
|
yield
|
|
|
|
logger.info { "done: #{elapsed(start)} sec" }
|
2012-08-29 23:20:20 -04:00
|
|
|
rescue Exception
|
2012-05-15 22:44:35 -04:00
|
|
|
logger.info { "fail: #{elapsed(start)} sec" }
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
end
|
2012-02-25 16:43:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def elapsed(start)
|
|
|
|
(Time.now - start).to_f.round(3)
|
|
|
|
end
|
|
|
|
|
|
|
|
def logger
|
2012-05-15 22:44:35 -04:00
|
|
|
Sidekiq.logger
|
2012-02-25 16:43:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|