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:
parent
dae5debf84
commit
614d41585b
7 changed files with 28 additions and 17 deletions
|
@ -6,6 +6,7 @@ HEAD
|
||||||
---------
|
---------
|
||||||
|
|
||||||
- Minimize scheduler load on Redis at scale [#4882]
|
- Minimize scheduler load on Redis at scale [#4882]
|
||||||
|
- Improve logging of delay jobs [#4904, BuonOno]
|
||||||
|
|
||||||
6.2.1
|
6.2.1
|
||||||
---------
|
---------
|
||||||
|
|
|
@ -316,21 +316,23 @@ module Sidekiq
|
||||||
|
|
||||||
def display_class
|
def display_class
|
||||||
# Unwrap known wrappers so they show up in a human-friendly manner in the Web UI
|
# Unwrap known wrappers so they show up in a human-friendly manner in the Web UI
|
||||||
@klass ||= case klass
|
@klass ||= self["display_class"] || begin
|
||||||
when /\ASidekiq::Extensions::Delayed/
|
case klass
|
||||||
safe_load(args[0], klass) do |target, method, _|
|
when /\ASidekiq::Extensions::Delayed/
|
||||||
"#{target}.#{method}"
|
safe_load(args[0], klass) do |target, method, _|
|
||||||
end
|
"#{target}.#{method}"
|
||||||
when "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper"
|
end
|
||||||
job_class = @item["wrapped"] || args[0]
|
when "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper"
|
||||||
if job_class == "ActionMailer::DeliveryJob" || job_class == "ActionMailer::MailDeliveryJob"
|
job_class = @item["wrapped"] || args[0]
|
||||||
# MailerClass#mailer_method
|
if job_class == "ActionMailer::DeliveryJob" || job_class == "ActionMailer::MailDeliveryJob"
|
||||||
args[0]["arguments"][0..1].join("#")
|
# MailerClass#mailer_method
|
||||||
else
|
args[0]["arguments"][0..1].join("#")
|
||||||
job_class
|
else
|
||||||
end
|
job_class
|
||||||
else
|
end
|
||||||
klass
|
else
|
||||||
|
klass
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,9 @@ module Sidekiq
|
||||||
if marshalled.size > SIZE_LIMIT
|
if marshalled.size > SIZE_LIMIT
|
||||||
::Sidekiq.logger.warn { "#{@target}.#{name} job argument is #{marshalled.bytesize} bytes, you should refactor it to reduce the size" }
|
::Sidekiq.logger.warn { "#{@target}.#{name} job argument is #{marshalled.bytesize} bytes, you should refactor it to reduce the size" }
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,7 +38,7 @@ module Sidekiq
|
||||||
# If we're using a wrapper class, like ActiveJob, use the "wrapped"
|
# If we're using a wrapper class, like ActiveJob, use the "wrapped"
|
||||||
# attribute to expose the underlying thing.
|
# attribute to expose the underlying thing.
|
||||||
h = {
|
h = {
|
||||||
class: job_hash["wrapped"] || job_hash["class"],
|
class: job_hash["display_class"] || job_hash["wrapped"] || job_hash["class"],
|
||||||
jid: job_hash["jid"]
|
jid: job_hash["jid"]
|
||||||
}
|
}
|
||||||
h[:bid] = job_hash["bid"] if job_hash["bid"]
|
h[:bid] = job_hash["bid"] if job_hash["bid"]
|
||||||
|
|
|
@ -2,4 +2,8 @@ class Post < ActiveRecord::Base
|
||||||
def long_method(other_post)
|
def long_method(other_post)
|
||||||
puts "Running long method with #{self.id} and #{other_post.id}"
|
puts "Running long method with #{self.id} and #{other_post.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.testing
|
||||||
|
Sidekiq.logger.info "Test"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,3 +33,4 @@ class TimedWorker
|
||||||
end
|
end
|
||||||
|
|
||||||
Sidekiq::Extensions.enable_delay!
|
Sidekiq::Extensions.enable_delay!
|
||||||
|
Post.delay.testing
|
||||||
|
|
|
@ -31,6 +31,7 @@ describe Sidekiq::Extensions do
|
||||||
assert_equal 0, q.size
|
assert_equal 0, q.size
|
||||||
MyModel.delay(queue: :notdefault).long_class_method
|
MyModel.delay(queue: :notdefault).long_class_method
|
||||||
assert_equal ['notdefault'], Sidekiq::Queue.all.map(&:name)
|
assert_equal ['notdefault'], Sidekiq::Queue.all.map(&:name)
|
||||||
|
assert_equal ['MyModel.long_class_method'], q.map(&:display_class)
|
||||||
assert_equal 1, q.size
|
assert_equal 1, q.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue