1
0
Fork 0
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:
Mike Perham 2015-03-23 15:16:07 -07:00
parent 4a0f314d8a
commit 8d2b1406bc
2 changed files with 22 additions and 7 deletions

View file

@ -18,17 +18,19 @@ module ActiveJob
def enqueue(job) #:nodoc: def enqueue(job) #:nodoc:
#Sidekiq::Client does not support symbols as keys #Sidekiq::Client does not support symbols as keys
Sidekiq::Client.push \ Sidekiq::Client.push \
'class' => JobWrapper, 'class' => JobWrapper,
'queue' => job.queue_name, 'wrapped' => job.class.to_s,
'args' => [ job.serialize ] 'queue' => job.queue_name,
'args' => [ job.serialize ]
end end
def enqueue_at(job, timestamp) #:nodoc: def enqueue_at(job, timestamp) #:nodoc:
Sidekiq::Client.push \ Sidekiq::Client.push \
'class' => JobWrapper, 'class' => JobWrapper,
'queue' => job.queue_name, 'wrapped' => job.class.to_s,
'args' => [ job.serialize ], 'queue' => job.queue_name,
'at' => timestamp 'args' => [ job.serialize ],
'at' => timestamp
end end
class JobWrapper #:nodoc: class JobWrapper #:nodoc:

View file

@ -1,5 +1,6 @@
require 'helper' require 'helper'
require 'jobs/logging_job' require 'jobs/logging_job'
require 'jobs/hello_job'
require 'active_support/core_ext/numeric/time' require 'active_support/core_ext/numeric/time'
class QueuingTest < ActiveSupport::TestCase class QueuingTest < ActiveSupport::TestCase
@ -23,6 +24,18 @@ class QueuingTest < ActiveSupport::TestCase
end end
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 test 'should not run job enqueued in the future' do
begin begin
TestJob.set(wait: 10.minutes).perform_later @id TestJob.set(wait: 10.minutes).perform_later @id