mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix accessing provider_job_id inside active jobs for sidekiq adapter
This commit is contained in:
parent
a64d9835f1
commit
80e825915c
4 changed files with 18 additions and 1 deletions
|
@ -105,6 +105,7 @@ module ActiveJob
|
|||
# end
|
||||
def deserialize(job_data)
|
||||
self.job_id = job_data['job_id']
|
||||
self.provider_job_id = job_data['provider_job_id']
|
||||
self.queue_name = job_data['queue_name']
|
||||
self.priority = job_data['priority']
|
||||
self.serialized_arguments = job_data['arguments']
|
||||
|
|
|
@ -37,7 +37,7 @@ module ActiveJob
|
|||
include Sidekiq::Worker
|
||||
|
||||
def perform(job_data)
|
||||
Base.execute job_data
|
||||
Base.execute job_data.merge('provider_job_id' => jid)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'helper'
|
||||
require 'jobs/logging_job'
|
||||
require 'jobs/hello_job'
|
||||
require 'jobs/provider_jid_job'
|
||||
require 'active_support/core_ext/numeric/time'
|
||||
|
||||
class QueuingTest < ActiveSupport::TestCase
|
||||
|
@ -34,6 +35,14 @@ class QueuingTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'should access provider_job_id inside Sidekiq job' do
|
||||
skip unless adapter_is?(:sidekiq)
|
||||
Sidekiq::Testing.inline! do
|
||||
job = ::ProviderJidJob.perform_later
|
||||
assert_equal "Provider Job ID: #{job.provider_job_id}", JobBuffer.last_value
|
||||
end
|
||||
end
|
||||
|
||||
test 'should not run job enqueued in the future' do
|
||||
begin
|
||||
TestJob.set(wait: 10.minutes).perform_later @id
|
||||
|
|
7
activejob/test/jobs/provider_jid_job.rb
Normal file
7
activejob/test/jobs/provider_jid_job.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require_relative '../support/job_buffer'
|
||||
|
||||
class ProviderJidJob < ActiveJob::Base
|
||||
def perform
|
||||
JobBuffer.add("Provider Job ID: #{provider_job_id}")
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue