From 29fcbc2ea0dc5ee2d8f512295f2ad3fac83f9941 Mon Sep 17 00:00:00 2001 From: Jeroen van Baarsen Date: Thu, 7 May 2015 17:25:49 +0200 Subject: Make que report back its job_id to provider_job_id Signed-off-by: Jeroen van Baarsen --- activejob/CHANGELOG.md | 11 +++-------- activejob/lib/active_job/queue_adapters/que_adapter.rb | 8 ++++++-- activejob/test/integration/queuing_test.rb | 14 ++++---------- 3 files changed, 13 insertions(+), 20 deletions(-) (limited to 'activejob') diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md index 9c5806a4db..45cebb9609 100644 --- a/activejob/CHANGELOG.md +++ b/activejob/CHANGELOG.md @@ -1,14 +1,9 @@ -* Allow `Sidekiq` to report the job id back to `ActiveJob::Base` as - `provider_job_id` - - *Jeroen van Baarsen* - -* Allow `DelayedJob` to report id back to `ActiveJob::Base` as - `provider_job_id`. +* Allow `DelayedJob`, `Sidekiq` and `que` to report the job id back to + `ActiveJob::Base` as `provider_job_id`. Fixes #18821. - *Kevin Deisz* + *Kevin Deisz* And *Jeroen van Baarsen* * `assert_enqueued_jobs` and `assert_performed_jobs` in block form use the given number as expected value. This makes the error message much easier to diff --git a/activejob/lib/active_job/queue_adapters/que_adapter.rb b/activejob/lib/active_job/queue_adapters/que_adapter.rb index a1a41ccc32..90947aa98d 100644 --- a/activejob/lib/active_job/queue_adapters/que_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/que_adapter.rb @@ -16,11 +16,15 @@ module ActiveJob # Rails.application.config.active_job.queue_adapter = :que class QueAdapter def enqueue(job) #:nodoc: - JobWrapper.enqueue job.serialize + que_job = JobWrapper.enqueue job.serialize + job.provider_job_id = que_job.attrs["job_id"] + que_job end def enqueue_at(job, timestamp) #:nodoc: - JobWrapper.enqueue job.serialize, run_at: Time.at(timestamp) + que_job = JobWrapper.enqueue job.serialize, run_at: Time.at(timestamp) + job.provider_job_id = que_job.attrs["job_id"] + que_job end class JobWrapper < Que::Job #:nodoc: diff --git a/activejob/test/integration/queuing_test.rb b/activejob/test/integration/queuing_test.rb index f2665221b8..14fdfa59f0 100644 --- a/activejob/test/integration/queuing_test.rb +++ b/activejob/test/integration/queuing_test.rb @@ -56,19 +56,13 @@ class QueuingTest < ActiveSupport::TestCase end end - test 'should supply a provider_job_id to DelayedJob' do - skip unless adapter_is?(:delayed_job) + test 'should supply a provider_job_id when available' do + skip unless adapter_is?(:sidekiq) || adapter_is?(:que) || adapter_is?(:delayed_job) test_job = TestJob.perform_later @id - assert_kind_of Fixnum, test_job.provider_job_id - end - - test 'should supply a provider_job_id to Sidekiq' do - skip unless adapter_is?(:sidekiq) - test_job = TestJob.perform_later @id - refute test_job.provider_job_id.nil?, "Provider job id should be set by Sidekiq" + refute test_job.provider_job_id.nil?, "Provider job id should be set by provider" delayed_test_job = TestJob.set(wait: 1.minute).perform_later @id refute delayed_test_job.provider_job_id.nil?, - "Provider job id should by set for delayed jobs by sidekiq" + "Provider job id should by set for delayed jobs by provider" end end -- cgit v1.2.3