aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Deisz <kevin.deisz@gmail.com>2015-04-26 13:05:08 -0400
committerKevin Deisz <kevin.deisz@gmail.com>2015-05-05 10:30:16 -0400
commitdd8e859829bfcfd8cb0287ce804055b827a35af1 (patch)
tree71a31b6996d3b81766ff33eddf2f2d995b02d6b7
parent918aa6e87813c5c7687e5d460c5cd62ba3919536 (diff)
downloadrails-dd8e859829bfcfd8cb0287ce804055b827a35af1.tar.gz
rails-dd8e859829bfcfd8cb0287ce804055b827a35af1.tar.bz2
rails-dd8e859829bfcfd8cb0287ce804055b827a35af1.zip
Get provider_job_id from DelayedJob
When queueing with DelayedJob, get the id of the job instance and report it back to ActiveJob as provider_job_id.
-rw-r--r--activejob/CHANGELOG.md7
-rw-r--r--activejob/lib/active_job/core.rb3
-rw-r--r--activejob/lib/active_job/queue_adapters/delayed_job_adapter.rb8
-rw-r--r--activejob/test/integration/queuing_test.rb6
4 files changed, 22 insertions, 2 deletions
diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md
index 1c55c1a4b8..6f9aa76a1f 100644
--- a/activejob/CHANGELOG.md
+++ b/activejob/CHANGELOG.md
@@ -1,3 +1,10 @@
+* Allow `DelayedJob` to report id back to `ActiveJob::Base` as
+ `provider_job_id`.
+
+ Fixes #18821.
+
+ *Kevin Deisz*
+
* `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
understand.
diff --git a/activejob/lib/active_job/core.rb b/activejob/lib/active_job/core.rb
index acdfcdc791..0528572cd0 100644
--- a/activejob/lib/active_job/core.rb
+++ b/activejob/lib/active_job/core.rb
@@ -17,6 +17,9 @@ module ActiveJob
# Queue in which the job will reside.
attr_writer :queue_name
+
+ # ID optionally provided by adapter
+ attr_accessor :provider_job_id
end
# These methods will be included into any Active Job object, adding
diff --git a/activejob/lib/active_job/queue_adapters/delayed_job_adapter.rb b/activejob/lib/active_job/queue_adapters/delayed_job_adapter.rb
index 852a6ee326..ac83da2b9c 100644
--- a/activejob/lib/active_job/queue_adapters/delayed_job_adapter.rb
+++ b/activejob/lib/active_job/queue_adapters/delayed_job_adapter.rb
@@ -14,11 +14,15 @@ module ActiveJob
# Rails.application.config.active_job.queue_adapter = :delayed_job
class DelayedJobAdapter
def enqueue(job) #:nodoc:
- Delayed::Job.enqueue(JobWrapper.new(job.serialize), queue: job.queue_name)
+ delayed_job = Delayed::Job.enqueue(JobWrapper.new(job.serialize), queue: job.queue_name)
+ job.provider_job_id = delayed_job.id
+ delayed_job
end
def enqueue_at(job, timestamp) #:nodoc:
- Delayed::Job.enqueue(JobWrapper.new(job.serialize), queue: job.queue_name, run_at: Time.at(timestamp))
+ delayed_job = Delayed::Job.enqueue(JobWrapper.new(job.serialize), queue: job.queue_name, run_at: Time.at(timestamp))
+ job.provider_job_id = delayed_job.id
+ delayed_job
end
class JobWrapper #:nodoc:
diff --git a/activejob/test/integration/queuing_test.rb b/activejob/test/integration/queuing_test.rb
index 96794ffef3..403b803558 100644
--- a/activejob/test/integration/queuing_test.rb
+++ b/activejob/test/integration/queuing_test.rb
@@ -55,4 +55,10 @@ class QueuingTest < ActiveSupport::TestCase
skip
end
end
+
+ test 'should supply a provider_job_id to DelayedJob' do
+ skip unless adapter_is?(:delayed_job)
+ test_job = TestJob.perform_later @id
+ assert_kind_of Fixnum, test_job.provider_job_id
+ end
end