mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Pass wrapped class name to Sidekiq for logging purposes
Sidekiq logs the name of the job class being performed. Because ActiveJob wraps the class, this means every job logs as an AJ::JobWrapper instead of the actual class name. Will help fix mperham/sidekiq#2248
This commit is contained in:
parent
4a0f314d8a
commit
8d2b1406bc
2 changed files with 22 additions and 7 deletions
|
@ -18,17 +18,19 @@ module ActiveJob
|
|||
def enqueue(job) #:nodoc:
|
||||
#Sidekiq::Client does not support symbols as keys
|
||||
Sidekiq::Client.push \
|
||||
'class' => JobWrapper,
|
||||
'queue' => job.queue_name,
|
||||
'args' => [ job.serialize ]
|
||||
'class' => JobWrapper,
|
||||
'wrapped' => job.class.to_s,
|
||||
'queue' => job.queue_name,
|
||||
'args' => [ job.serialize ]
|
||||
end
|
||||
|
||||
def enqueue_at(job, timestamp) #:nodoc:
|
||||
Sidekiq::Client.push \
|
||||
'class' => JobWrapper,
|
||||
'queue' => job.queue_name,
|
||||
'args' => [ job.serialize ],
|
||||
'at' => timestamp
|
||||
'class' => JobWrapper,
|
||||
'wrapped' => job.class.to_s,
|
||||
'queue' => job.queue_name,
|
||||
'args' => [ job.serialize ],
|
||||
'at' => timestamp
|
||||
end
|
||||
|
||||
class JobWrapper #:nodoc:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'helper'
|
||||
require 'jobs/logging_job'
|
||||
require 'jobs/hello_job'
|
||||
require 'active_support/core_ext/numeric/time'
|
||||
|
||||
class QueuingTest < ActiveSupport::TestCase
|
||||
|
@ -23,6 +24,18 @@ class QueuingTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'should supply a wrapped class name to Sidekiq' do
|
||||
skip unless adapter_is?(:sidekiq)
|
||||
require 'sidekiq/testing'
|
||||
|
||||
Sidekiq::Testing.fake! do
|
||||
::HelloJob.perform_later
|
||||
hash = ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper.jobs.first
|
||||
assert_equal "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", hash['class']
|
||||
assert_equal "HelloJob", hash['wrapped']
|
||||
end
|
||||
end
|
||||
|
||||
test 'should not run job enqueued in the future' do
|
||||
begin
|
||||
TestJob.set(wait: 10.minutes).perform_later @id
|
||||
|
|
Loading…
Reference in a new issue