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

32 lines
677 B
Ruby
Raw Normal View History

2012-02-25 16:43:53 -05:00
module Sidekiq
module Middleware
module Server
class Logging
2012-02-25 16:43:53 -05:00
def call(*args)
Sidekiq::Logging.with_context("#{args[0].class.to_s} MSG-#{args[0].object_id.to_s(36)}") do
begin
start = Time.now
logger.info { "start" }
yield
logger.info { "done: #{elapsed(start)} sec" }
rescue
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
Sidekiq.logger
2012-02-25 16:43:53 -05:00
end
end
end
end
end