aboutsummaryrefslogtreecommitdiffstats
path: root/activejob
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-05-07 16:37:29 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-05-07 16:37:29 -0300
commitd84bfaa8530e42188f0361efb5a61c73948192e6 (patch)
treefd5bd31589bf3c5637d9dd8215d86f9d655478f6 /activejob
parent0a5a6c0c3679872de47e5d5091963e6a6eee06b8 (diff)
parentdd8e859829bfcfd8cb0287ce804055b827a35af1 (diff)
downloadrails-d84bfaa8530e42188f0361efb5a61c73948192e6.tar.gz
rails-d84bfaa8530e42188f0361efb5a61c73948192e6.tar.bz2
rails-d84bfaa8530e42188f0361efb5a61c73948192e6.zip
Merge pull request #19910 from kddeisz/delayed_job_provider_job_id
Get provider_job_id from DelayedJob
Diffstat (limited to 'activejob')
-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