mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Add keyword arguments handler in Sidekiq::JobRecord#display_args (#5134)
* Add keyword arguments handler in Sidekiq::JobRecord#display_args * Update Sidekiq::JobRecord#display_args kwargs's presence check so that we are not dependent on Rails.
This commit is contained in:
parent
df20201949
commit
10e7feb312
2 changed files with 14 additions and 6 deletions
|
@ -355,8 +355,12 @@ module Sidekiq
|
|||
# Unwrap known wrappers so they show up in a human-friendly manner in the Web UI
|
||||
@display_args ||= case klass
|
||||
when /\ASidekiq::Extensions::Delayed/
|
||||
safe_load(args[0], args) do |_, _, arg|
|
||||
arg
|
||||
safe_load(args[0], args) do |_, _, arg, kwarg|
|
||||
if !kwarg || kwarg.empty?
|
||||
arg
|
||||
else
|
||||
[arg, kwarg]
|
||||
end
|
||||
end
|
||||
when "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper"
|
||||
job_args = self["wrapped"] ? args[0]["arguments"] : []
|
||||
|
|
|
@ -33,11 +33,12 @@ describe Sidekiq::Extensions do
|
|||
assert_equal [], Sidekiq::Queue.all.map(&:name)
|
||||
q = Sidekiq::Queue.new
|
||||
assert_equal 0, q.size
|
||||
MyModel.delay.long_class_method_with_optional_args(with: :keywords)
|
||||
MyModel.delay.long_class_method_with_optional_args("argument_a", "argument_b", with: :keywords)
|
||||
assert_equal ['default'], Sidekiq::Queue.all.map(&:name)
|
||||
assert_equal 1, q.size
|
||||
obj = YAML.load q.first['args'].first
|
||||
assert_equal({ with: :keywords }, obj.last)
|
||||
assert_equal([["argument_a", "argument_b"], { with: :keywords }], q.first.display_args)
|
||||
end
|
||||
|
||||
it 'forwards the keyword arguments to perform' do
|
||||
|
@ -92,11 +93,12 @@ describe Sidekiq::Extensions do
|
|||
assert_equal [], Sidekiq::Queue.all.map(&:name)
|
||||
q = Sidekiq::Queue.new
|
||||
assert_equal 0, q.size
|
||||
UserMailer.delay.greetings_with_optional_args(with: :keywords)
|
||||
UserMailer.delay.greetings_with_optional_args("argument_a", "argument_b", with: :keywords)
|
||||
assert_equal ['default'], Sidekiq::Queue.all.map(&:name)
|
||||
assert_equal 1, q.size
|
||||
obj = YAML.load q.first['args'].first
|
||||
assert_equal({ with: :keywords }, obj.last)
|
||||
assert_equal([["argument_a", "argument_b"], { with: :keywords }], q.first.display_args)
|
||||
end
|
||||
|
||||
it 'allows delayed scheduling of AM mails' do
|
||||
|
@ -132,10 +134,11 @@ describe Sidekiq::Extensions do
|
|||
it 'allows delay of any ole class method with optional arguments' do
|
||||
q = Sidekiq::Queue.new
|
||||
assert_equal 0, q.size
|
||||
SomeClass.delay.doit_with_optional_args(with: :keywords)
|
||||
SomeClass.delay.doit_with_optional_args("argument_a", "argument_b", with: :keywords)
|
||||
assert_equal 1, q.size
|
||||
obj = YAML.load q.first['args'].first
|
||||
assert_equal({ with: :keywords }, obj.last)
|
||||
assert_equal([["argument_a", "argument_b"], { with: :keywords }], q.first.display_args)
|
||||
end
|
||||
|
||||
it 'forwards the keyword arguments to perform' do
|
||||
|
@ -170,10 +173,11 @@ describe Sidekiq::Extensions do
|
|||
it 'allows delay of any module class method with optional arguments' do
|
||||
q = Sidekiq::Queue.new
|
||||
assert_equal 0, q.size
|
||||
SomeModule.delay.doit_with_optional_args(with: :keywords)
|
||||
SomeModule.delay.doit_with_optional_args("argument_a", "argument_b", with: :keywords)
|
||||
assert_equal 1, q.size
|
||||
obj = YAML.load q.first['args'].first
|
||||
assert_equal({ with: :keywords }, obj.last)
|
||||
assert_equal([["argument_a", "argument_b"], { with: :keywords }], q.first.display_args)
|
||||
end
|
||||
|
||||
it 'forwards the keyword arguments to perform' do
|
||||
|
|
Loading…
Reference in a new issue