diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2018-12-05 13:37:48 -0500 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2018-12-05 13:52:44 -0500 |
commit | 884310fdd031ed8121944f9ea07c8b7723c4e6b6 (patch) | |
tree | 626ade08923335b89f533a2311f4cf34ea163394 /activejob | |
parent | b802e08273f899d5f3b199f7c6a4f5d514c1b0e1 (diff) | |
download | rails-884310fdd031ed8121944f9ea07c8b7723c4e6b6.tar.gz rails-884310fdd031ed8121944f9ea07c8b7723c4e6b6.tar.bz2 rails-884310fdd031ed8121944f9ea07c8b7723c4e6b6.zip |
Improve deprecation message for enqueue returning false
And make sure new applications in Rails 6.0 has this config enabled.
Also, improve test coverage and add a CHANGELOG entry.
Diffstat (limited to 'activejob')
-rw-r--r-- | activejob/CHANGELOG.md | 7 | ||||
-rw-r--r-- | activejob/lib/active_job/enqueuing.rb | 10 |
2 files changed, 16 insertions, 1 deletions
diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md index 8e18faeb02..4acbe9a4e9 100644 --- a/activejob/CHANGELOG.md +++ b/activejob/CHANGELOG.md @@ -1,3 +1,10 @@ +* Return false instead of the job instance when `enqueue` is aborted. + + This will be the behavior in Rails 6.1 but it can be controlled now with + `config.active_job.return_false_on_aborted_enqueue`. + + *Kir Shatrov* + * Keep executions for each specific declaration Each `retry_on` declaration has now its own specific executions counter. Before it was diff --git a/activejob/lib/active_job/enqueuing.rb b/activejob/lib/active_job/enqueuing.rb index 58e6d3348d..ce118c1e8a 100644 --- a/activejob/lib/active_job/enqueuing.rb +++ b/activejob/lib/active_job/enqueuing.rb @@ -49,21 +49,29 @@ module ActiveJob 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." + ActiveSupport::Deprecation.warn( + "Rails 6.0 will return false when the enqueing is aborted. Make sure your code doesn't depend on it" \ + " returning the instance of the job and set `config.active_job.return_false_on_aborted_enqueue = true`" \ + " to remove the deprecations." + ) + self end end |