diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-05-08 15:13:05 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-05-08 15:13:05 -0300 |
commit | fca8a7a7ba4047d3843219f9403c059f40fe0de2 (patch) | |
tree | 2c4055f11ebe7d134d04a08d3eb4a1e4ce5960dc | |
parent | 7b975c54d1e8c70bfeb82b15303ab18204de7b33 (diff) | |
parent | 221a411fd79a25c062100e43423188df5ac4bf2f (diff) | |
download | rails-fca8a7a7ba4047d3843219f9403c059f40fe0de2.tar.gz rails-fca8a7a7ba4047d3843219f9403c059f40fe0de2.tar.bz2 rails-fca8a7a7ba4047d3843219f9403c059f40fe0de2.zip |
Merge pull request #20064 from kddeisz/qu_provider_job_id
Provide provider_job_id to qu adapter.
-rw-r--r-- | activejob/CHANGELOG.md | 2 | ||||
-rw-r--r-- | activejob/lib/active_job/queue_adapters/qu_adapter.rb | 6 | ||||
-rw-r--r-- | activejob/test/integration/queuing_test.rb | 13 | ||||
-rw-r--r-- | activejob/test/support/integration/test_case_helpers.rb | 4 |
4 files changed, 16 insertions, 9 deletions
diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md index 45cebb9609..74f4c2588e 100644 --- a/activejob/CHANGELOG.md +++ b/activejob/CHANGELOG.md @@ -1,4 +1,4 @@ -* Allow `DelayedJob`, `Sidekiq` and `que` to report the job id back to +* Allow `DelayedJob`, `Sidekiq`, `qu`, and `que` to report the job id back to `ActiveJob::Base` as `provider_job_id`. Fixes #18821. diff --git a/activejob/lib/active_job/queue_adapters/qu_adapter.rb b/activejob/lib/active_job/queue_adapters/qu_adapter.rb index 36f4c14911..0e198922fc 100644 --- a/activejob/lib/active_job/queue_adapters/qu_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/qu_adapter.rb @@ -17,9 +17,13 @@ module ActiveJob # Rails.application.config.active_job.queue_adapter = :qu class QuAdapter def enqueue(job, *args) #:nodoc: - Qu::Payload.new(klass: JobWrapper, args: [job.serialize]).tap do |payload| + qu_job = Qu::Payload.new(klass: JobWrapper, args: [job.serialize]).tap do |payload| payload.instance_variable_set(:@queue, job.queue_name) end.push + + # qu_job can be nil depending on the configured backend + job.provider_job_id = qu_job.id unless qu_job.nil? + qu_job end def enqueue_at(job, timestamp, *args) #:nodoc: diff --git a/activejob/test/integration/queuing_test.rb b/activejob/test/integration/queuing_test.rb index 14fdfa59f0..d345092dee 100644 --- a/activejob/test/integration/queuing_test.rb +++ b/activejob/test/integration/queuing_test.rb @@ -11,7 +11,7 @@ class QueuingTest < ActiveSupport::TestCase end test 'should not run jobs queued on a non-listening queue' do - skip if adapter_is?(:inline) || adapter_is?(:sucker_punch) || adapter_is?(:que) + skip if adapter_is?(:inline, :sucker_punch, :que) old_queue = TestJob.queue_name begin @@ -56,13 +56,16 @@ class QueuingTest < ActiveSupport::TestCase end end - test 'should supply a provider_job_id when available' do - skip unless adapter_is?(:sidekiq) || adapter_is?(:que) || adapter_is?(:delayed_job) + test 'should supply a provider_job_id when available for immediate jobs' do + skip unless adapter_is?(:delayed_job, :sidekiq, :qu, :que) test_job = TestJob.perform_later @id - refute test_job.provider_job_id.nil?, "Provider job id should be set by provider" + refute test_job.provider_job_id.nil?, 'Provider job id should be set by provider' + end + test 'should supply a provider_job_id when available for delayed jobs' do + skip unless adapter_is?(:delayed_job, :sidekiq, :que) 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 provider" + 'Provider job id should by set for delayed jobs by provider' end end diff --git a/activejob/test/support/integration/test_case_helpers.rb b/activejob/test/support/integration/test_case_helpers.rb index bed28b2900..7e87ede275 100644 --- a/activejob/test/support/integration/test_case_helpers.rb +++ b/activejob/test/support/integration/test_case_helpers.rb @@ -27,8 +27,8 @@ module TestCaseHelpers jobs_manager.clear_jobs end - def adapter_is?(adapter_class_symbol) - ActiveJob::Base.queue_adapter.class.name.split("::").last.gsub(/Adapter$/, '').underscore == adapter_class_symbol.to_s + def adapter_is?(*adapter_class_symbols) + adapter_class_symbols.map(&:to_s).include?(ActiveJob::Base.queue_adapter.class.name.split("::").last.gsub(/Adapter$/, '').underscore) end def wait_for_jobs_to_finish_for(seconds=60) |