1
0
Fork 0
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:
Azzurrio 2016-07-26 23:46:03 +02:00
parent a64d9835f1
commit 80e825915c
4 changed files with 18 additions and 1 deletions

View file

@ -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']

View file

@ -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

View file

@ -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

View 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