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/middleware/server/logging.rb
2012-11-03 11:47:48 -07:00

31 lines
685 B
Ruby

module Sidekiq
module Middleware
module Server
class Logging
def call(worker, item, queue)
Sidekiq::Logging.with_context("#{worker.class.to_s} JID-#{item['jid']}") do
begin
start = Time.now
logger.info { "start" }
yield
logger.info { "done: #{elapsed(start)} sec" }
rescue Exception
logger.info { "fail: #{elapsed(start)} sec" }
raise
end
end
end
def elapsed(start)
(Time.now - start).to_f.round(3)
end
def logger
Sidekiq.logger
end
end
end
end
end