diff options
author | Kir Shatrov <shatrov@me.com> | 2018-09-26 17:25:20 +0100 |
---|---|---|
committer | Kir Shatrov <shatrov@me.com> | 2018-10-28 15:02:44 -0400 |
commit | ee9fc120242b83c64bf77af1b72082ac76319332 (patch) | |
tree | 7b9fef67646c221c85c71be236d8bd50ffa2c7e4 /activejob/lib | |
parent | 3295e23755744b7f9426d752481bb928fb02a89e (diff) | |
download | rails-ee9fc120242b83c64bf77af1b72082ac76319332.tar.gz rails-ee9fc120242b83c64bf77af1b72082ac76319332.tar.bz2 rails-ee9fc120242b83c64bf77af1b72082ac76319332.zip |
Make AJ::Base#enqueue return false if the job wasn't enqueued
Diffstat (limited to 'activejob/lib')
-rw-r--r-- | activejob/lib/active_job/callbacks.rb | 3 | ||||
-rw-r--r-- | activejob/lib/active_job/enqueuing.rb | 13 |
2 files changed, 15 insertions, 1 deletions
diff --git a/activejob/lib/active_job/callbacks.rb b/activejob/lib/active_job/callbacks.rb index 334b24fb3b..e0e48d3ef5 100644 --- a/activejob/lib/active_job/callbacks.rb +++ b/activejob/lib/active_job/callbacks.rb @@ -29,6 +29,9 @@ module ActiveJob included do define_callbacks :perform define_callbacks :enqueue + + class_attribute :return_false_on_aborted_enqueue, instance_accessor: false, instance_predicate: false + self.return_false_on_aborted_enqueue = false end # These methods will be included into any Active Job object, adding diff --git a/activejob/lib/active_job/enqueuing.rb b/activejob/lib/active_job/enqueuing.rb index 53cb98fc71..5be5618390 100644 --- a/activejob/lib/active_job/enqueuing.rb +++ b/activejob/lib/active_job/enqueuing.rb @@ -46,14 +46,25 @@ module ActiveJob self.scheduled_at = options[:wait_until].to_f if options[:wait_until] self.queue_name = self.class.queue_name_from_part(options[:queue]) if options[:queue] self.priority = options[:priority].to_i if options[:priority] + successfully_enqueued = false run_callbacks :enqueue do if scheduled_at self.class.queue_adapter.enqueue_at self, scheduled_at else self.class.queue_adapter.enqueue self end + successfully_enqueued = true + end + if successfully_enqueued + self + else + if self.class.return_false_on_aborted_enqueue + false + else + ActiveSupport::Deprecation.warn "this will return false, set config.active_job.return_false_on_aborted_enqueue = true to remove deprecation." + self + end end - self end end end |