1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Improve logging of .delay jobs, closes #4904

This commit is contained in:
Mike Perham 2021-05-24 12:29:45 -07:00
parent dae5debf84
commit 614d41585b
7 changed files with 28 additions and 17 deletions

View file

@ -6,6 +6,7 @@ HEAD
---------
- Minimize scheduler load on Redis at scale [#4882]
- Improve logging of delay jobs [#4904, BuonOno]
6.2.1
---------

View file

@ -316,21 +316,23 @@ module Sidekiq
def display_class
# Unwrap known wrappers so they show up in a human-friendly manner in the Web UI
@klass ||= case klass
when /\ASidekiq::Extensions::Delayed/
safe_load(args[0], klass) do |target, method, _|
"#{target}.#{method}"
end
when "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper"
job_class = @item["wrapped"] || args[0]
if job_class == "ActionMailer::DeliveryJob" || job_class == "ActionMailer::MailDeliveryJob"
# MailerClass#mailer_method
args[0]["arguments"][0..1].join("#")
else
job_class
end
else
klass
@klass ||= self["display_class"] || begin
case klass
when /\ASidekiq::Extensions::Delayed/
safe_load(args[0], klass) do |target, method, _|
"#{target}.#{method}"
end
when "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper"
job_class = @item["wrapped"] || args[0]
if job_class == "ActionMailer::DeliveryJob" || job_class == "ActionMailer::MailDeliveryJob"
# MailerClass#mailer_method
args[0]["arguments"][0..1].join("#")
else
job_class
end
else
klass
end
end
end

View file

@ -24,7 +24,9 @@ module Sidekiq
if marshalled.size > SIZE_LIMIT
::Sidekiq.logger.warn { "#{@target}.#{name} job argument is #{marshalled.bytesize} bytes, you should refactor it to reduce the size" }
end
@performable.client_push({"class" => @performable, "args" => [marshalled]}.merge(@opts))
@performable.client_push({"class" => @performable,
"args" => [marshalled],
"display_class" => "#{@target}.#{name}"}.merge(@opts))
end
end
end

View file

@ -38,7 +38,7 @@ module Sidekiq
# If we're using a wrapper class, like ActiveJob, use the "wrapped"
# attribute to expose the underlying thing.
h = {
class: job_hash["wrapped"] || job_hash["class"],
class: job_hash["display_class"] || job_hash["wrapped"] || job_hash["class"],
jid: job_hash["jid"]
}
h[:bid] = job_hash["bid"] if job_hash["bid"]

View file

@ -2,4 +2,8 @@ class Post < ActiveRecord::Base
def long_method(other_post)
puts "Running long method with #{self.id} and #{other_post.id}"
end
def self.testing
Sidekiq.logger.info "Test"
end
end

View file

@ -33,3 +33,4 @@ class TimedWorker
end
Sidekiq::Extensions.enable_delay!
Post.delay.testing

View file

@ -31,6 +31,7 @@ describe Sidekiq::Extensions do
assert_equal 0, q.size
MyModel.delay(queue: :notdefault).long_class_method
assert_equal ['notdefault'], Sidekiq::Queue.all.map(&:name)
assert_equal ['MyModel.long_class_method'], q.map(&:display_class)
assert_equal 1, q.size
end