aboutsummaryrefslogtreecommitdiffstats
path: root/activejob
diff options
context:
space:
mode:
authorJeroen van Baarsen <jeroenvanbaarsen@gmail.com>2015-05-07 17:25:49 +0200
committerJeroen van Baarsen <jeroenvanbaarsen@gmail.com>2015-05-07 21:59:07 +0200
commit29fcbc2ea0dc5ee2d8f512295f2ad3fac83f9941 (patch)
treebe0e093df62add6a96c9860df3895b3f6fb5947f /activejob
parent52d131826e46d1a4606b71ddbf57db0f75f040e0 (diff)
downloadrails-29fcbc2ea0dc5ee2d8f512295f2ad3fac83f9941.tar.gz
rails-29fcbc2ea0dc5ee2d8f512295f2ad3fac83f9941.tar.bz2
rails-29fcbc2ea0dc5ee2d8f512295f2ad3fac83f9941.zip
Make que report back its job_id to provider_job_id
Signed-off-by: Jeroen van Baarsen <jeroenvanbaarsen@gmail.com>
Diffstat (limited to 'activejob')
-rw-r--r--activejob/CHANGELOG.md11
-rw-r--r--activejob/lib/active_job/queue_adapters/que_adapter.rb8
-rw-r--r--activejob/test/integration/queuing_test.rb14
3 files changed, 13 insertions, 20 deletions
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