diff options
-rw-r--r-- | activejob/CHANGELOG.md | 7 | ||||
-rw-r--r-- | activejob/lib/active_job/enqueuing.rb | 10 | ||||
-rw-r--r-- | guides/source/configuring.md | 2 | ||||
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 4 | ||||
-rw-r--r-- | railties/test/application/configuration_test.rb | 27 |
5 files changed, 49 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 diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 960a43406b..029ae1a5ff 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -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 diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index d6f8c4f47c..f30e5d2a0f 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -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 diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 3635de7162..9fff764eca 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -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 ] |