1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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.
This commit is contained in:
Rafael Mendonça França 2018-12-05 13:37:48 -05:00
parent b802e08273
commit 884310fdd0
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
5 changed files with 49 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -782,6 +782,8 @@ There are a few configuration options available in Active Support:
* `config.active_job.custom_serializers` allows to set custom argument serializers. Defaults to `[]`.
* `config.active_job.return_false_on_aborted_enqueue` change the return value of `#enqueue` to false instead of the job instance when the enqueuing is aborted. Defaults to `false`.
### Configuring Action Cable
* `config.action_cable.url` accepts a string for the URL for where

View file

@ -127,6 +127,10 @@ module Rails
if respond_to?(:action_dispatch)
action_dispatch.use_cookies_with_metadata = true
end
if respond_to?(:active_job)
active_job.return_false_on_aborted_enqueue = true
end
else
raise "Unknown version #{target_version.to_s.inspect}"
end

View file

@ -2139,6 +2139,33 @@ module ApplicationTests
assert_equal false, ActionView::Template.finalize_compiled_template_methods
end
test "ActiveJob::Base.return_false_on_aborted_enqueue is true by default" do
app "development"
assert_equal true, ActiveJob::Base.return_false_on_aborted_enqueue
end
test "ActiveJob::Base.return_false_on_aborted_enqueue is false in the 5.x defaults" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "5.2"'
app "development"
assert_equal false, ActiveJob::Base.return_false_on_aborted_enqueue
end
test "ActiveJob::Base.return_false_on_aborted_enqueue can be configured in the new framework defaults" do
remove_from_config '.*config\.load_defaults.*\n'
app_file "config/initializers/new_framework_defaults_6_0.rb", <<-RUBY
Rails.application.config.active_job.return_false_on_aborted_enqueue = true
RUBY
app "development"
assert_equal true, ActiveJob::Base.return_false_on_aborted_enqueue
end
test "ActiveRecord::Base.filter_attributes should equal to filter_parameters" do
app_file "config/initializers/filter_parameters_logging.rb", <<-RUBY
Rails.application.config.filter_parameters += [ :password, :credit_card_number ]