mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
701e06224c
* Rework job processing in light of Rails 5's Reloader, see #3221 * Ignore built gems * Documentation, testing * Add fallback for 'retry' value server-side, fixes #3234 * Fix job hash reporting in stats * cleanup * Add job for AJ testing * Push jobs with invalid JSON immediately to Dead set, fixes #3296 * Break retry logic into global and local parts, fixes #3306 * fix heisentest
36 lines
837 B
Ruby
36 lines
837 B
Ruby
module Sidekiq
|
|
class JobLogger
|
|
|
|
def call(item, queue)
|
|
Sidekiq::Logging.with_context(log_context(item)) do
|
|
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
|
|
end
|
|
|
|
private
|
|
|
|
# If we're using a wrapper class, like ActiveJob, use the "wrapped"
|
|
# attribute to expose the underlying thing.
|
|
def log_context(item)
|
|
klass = item['wrapped'.freeze] || item["class".freeze]
|
|
"#{klass} JID-#{item['jid'.freeze]}#{" BID-#{item['bid'.freeze]}" if item['bid'.freeze]}"
|
|
end
|
|
|
|
def elapsed(start)
|
|
(Time.now - start).round(3)
|
|
end
|
|
|
|
def logger
|
|
Sidekiq.logger
|
|
end
|
|
end
|
|
end
|
|
|