mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
small refactor for Logging middleware
This commit is contained in:
parent
a64333bd1d
commit
8dd53611dd
1 changed files with 10 additions and 5 deletions
|
@ -4,11 +4,7 @@ module Sidekiq
|
|||
class Logging
|
||||
|
||||
def call(worker, item, queue)
|
||||
# If we're using a wrapper class, like ActiveJob, use the "wrapped"
|
||||
# attribute to expose the underlying thing.
|
||||
klass = item['wrapped'] || worker.class.to_s
|
||||
|
||||
Sidekiq::Logging.with_context("#{klass} JID-#{item['jid']}#{" BID-#{item['bid']}" if item['bid']}") do
|
||||
Sidekiq::Logging.with_context(log_context(worker, item)) do
|
||||
begin
|
||||
start = Time.now
|
||||
logger.info { "start" }
|
||||
|
@ -21,6 +17,15 @@ module Sidekiq
|
|||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# If we're using a wrapper class, like ActiveJob, use the "wrapped"
|
||||
# attribute to expose the underlying thing.
|
||||
def log_context(worker, item)
|
||||
klass = item['wrapped'.freeze] || worker.class.to_s
|
||||
"#{klass} JID-#{item['jid'.freeze]}#{" BID-#{item['bid'.freeze]}" if item['bid'.freeze]}"
|
||||
end
|
||||
|
||||
def elapsed(start)
|
||||
(Time.now - start).round(3)
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue