Skip to content

Commit

Permalink
Merge pull request #40766 from rafaelfranca/rm-queue-defaults
Browse files Browse the repository at this point in the history
Change default queue name of all the internal jobs to be the job adapter's default
  • Loading branch information
rafaelfranca committed Dec 8, 2020
1 parent 04a0c52 commit 45d1efa
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 12 deletions.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Railtie < Rails::Railtie # :nodoc:
config.active_record.maintain_test_schema = true
config.active_record.has_many_inversing = false

config.active_record.queues = ActiveSupport::InheritableOptions.new(destroy: :active_record_destroy)
config.active_record.queues = ActiveSupport::InheritableOptions.new

config.eager_load_namespaces << ActiveRecord

Expand Down
2 changes: 1 addition & 1 deletion activestorage/lib/active_storage/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Engine < Rails::Engine # :nodoc:
config.active_storage.previewers = [ ActiveStorage::Previewer::PopplerPDFPreviewer, ActiveStorage::Previewer::MuPDFPreviewer, ActiveStorage::Previewer::VideoPreviewer ]
config.active_storage.analyzers = [ ActiveStorage::Analyzer::ImageAnalyzer, ActiveStorage::Analyzer::VideoAnalyzer ]
config.active_storage.paths = ActiveSupport::OrderedOptions.new
config.active_storage.queues = ActiveSupport::InheritableOptions.new(mirror: :active_storage_mirror)
config.active_storage.queues = ActiveSupport::InheritableOptions.new

config.active_storage.variable_content_types = %w(
image/png
Expand Down
17 changes: 11 additions & 6 deletions guides/source/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ in controllers and views. This defaults to `false`.

* `config.active_record.destroy_association_async_job` allows specifying the job that will be used to destroy the associated records in background. It defaults to `ActiveRecord::DestroyAssociationAsyncJob`.

* `config.active_record.queues.destroy` allows specifying the Active Job queue to use for destroy jobs. It defaults to `:active_record_destroy`.
* `config.active_record.queues.destroy` allows specifying the Active Job queue to use for destroy jobs. When this option is `nil`, purge jobs are sent to the default Active Job queue (see `config.active_job.default_queue_name`). It defaults to `nil`.

The MySQL adapter adds one additional configuration option:

Expand Down Expand Up @@ -725,9 +725,9 @@ Defaults to `'signed cookie'`.
config.action_mailbox.incinerate_after = 14.days
```

* `config.action_mailbox.queues.incineration` accepts a symbol indicating the Active Job queue to use for incineration jobs. It defaults to `:action_mailbox_incineration`.
* `config.action_mailbox.queues.incineration` accepts a symbol indicating the Active Job queue to use for incineration jobs. When this option is `nil`, purge jobs are sent to the default Active Job queue (see `config.active_job.default_queue_name`). It defaults to `:action_mailbox_incineration`.

* `config.action_mailbox.queues.routing` accepts a symbol indicating the Active Job queue to use for routing jobs. It defaults to `:action_mailbox_routing`.
* `config.action_mailbox.queues.routing` accepts a symbol indicating the Active Job queue to use for routing jobs. When this option is `nil`, purge jobs are sent to the default Active Job queue (see `config.active_job.default_queue_name`). It defaults to `:action_mailbox_routing`.


### Configuring Action Mailer
Expand Down Expand Up @@ -956,19 +956,19 @@ text/javascript image/svg+xml application/postscript application/x-shockwave-fla

* `config.active_storage.content_types_allowed_inline` accepts an array of strings indicating the content types that Active Storage allows to serve as inline. The default is `%w(image/png image/gif image/jpg image/jpeg image/tiff image/bmp image/vnd.adobe.photoshop image/vnd.microsoft.icon application/pdf)`.

* `config.active_storage.queues.analysis` accepts a symbol indicating the Active Job queue to use for analysis jobs. When this option is `nil`, analysis jobs are sent to the default Active Job queue (see `config.active_job.default_queue_name`).
* `config.active_storage.queues.analysis` accepts a symbol indicating the Active Job queue to use for analysis jobs. When this option is `nil`, analysis jobs are sent to the default Active Job queue (see `config.active_job.default_queue_name`). The default is `nil`.

```ruby
config.active_storage.queues.analysis = :low_priority
```

* `config.active_storage.queues.purge` accepts a symbol indicating the Active Job queue to use for purge jobs. When this option is `nil`, purge jobs are sent to the default Active Job queue (see `config.active_job.default_queue_name`).
* `config.active_storage.queues.purge` accepts a symbol indicating the Active Job queue to use for purge jobs. When this option is `nil`, purge jobs are sent to the default Active Job queue (see `config.active_job.default_queue_name`). The default is `nil`.

```ruby
config.active_storage.queues.purge = :low_priority
```

* `config.active_storage.queues.mirror` accepts a symbol indicating the Active Job queue to use for direct upload mirroring jobs. The default is `:active_storage_mirror`.
* `config.active_storage.queues.mirror` accepts a symbol indicating the Active Job queue to use for direct upload mirroring jobs. When this option is `nil`, purge jobs are sent to the default Active Job queue (see `config.active_job.default_queue_name`). The default is `nil`.

```ruby
config.active_storage.queues.mirror = :low_priority
Expand Down Expand Up @@ -1018,6 +1018,11 @@ text/javascript image/svg+xml application/postscript application/x-shockwave-fla
- `config.active_record.has_many_inversing`: `true`
- `config.active_record.legacy_connection_handling`: `false`
- `config.active_storage.track_variants`: `true`
- `config.active_storage.queues.analysis`: `nil`
- `config.active_storage.queues.purge`: `nil`
- `config.action_mailbox.queues.incineration`: `nil`
- `config.action_mailbox.queues.routing`: `nil`
- `config.action_mailer.deliver_later_queue_name`: `nil`
- `config.active_job.retry_jitter`: `0.15`
- `config.active_job.skip_after_callbacks_if_terminated`: `true`
- `config.action_dispatch.cookies_same_site_protection`: `:lax`
Expand Down
14 changes: 14 additions & 0 deletions railties/lib/rails/application/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ def load_defaults(target_version)
action_view.form_with_generates_remote_forms = false
end

if respond_to?(:active_storage)
active_storage.queues.analysis = nil
active_storage.queues.purge = nil
end

if respond_to?(:action_mailbox)
action_mailbox.queues.incineration = nil
action_mailbox.queues.routing = nil
end

if respond_to?(:action_mailer)
action_mailer.deliver_later_queue_name = nil
end

ActiveSupport.utc_to_local_returns_utc_offset_times = true
when "6.2"
load_defaults "6.1"
Expand Down
93 changes: 89 additions & 4 deletions railties/test/application/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,29 @@ def index
assert_equal "test_default", ActionMailer::Base.class_variable_get(:@@deliver_later_queue_name)
end

test "ActionMailer::DeliveryJob queue name is :mailers without the Rails defaults" do
remove_from_config '.*config\.load_defaults.*\n'

app "development"

require "mail"
_ = ActionMailer::Base

assert_equal :mailers, ActionMailer::Base.class_variable_get(:@@deliver_later_queue_name)
end

test "ActionMailer::DeliveryJob queue name is nil by default in 6.1" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "6.1"'

app "development"

require "mail"
_ = ActionMailer::Base

assert_nil ActionMailer::Base.class_variable_get(:@@deliver_later_queue_name)
end

test "valid timezone is setup correctly" do
add_to_config <<-RUBY
config.root = "#{app_path}"
Expand Down Expand Up @@ -2449,12 +2472,24 @@ class ::DummySerializer < ActiveJob::Serializers::ObjectSerializer; end
assert_equal true, ActiveSupport.utc_to_local_returns_utc_offset_times
end

test "ActiveStorage.queues[:analysis] is :active_storage_analysis by default" do
test "ActiveStorage.queues[:analysis] is :active_storage_analysis by default in 6.0" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "6.0"'

app "development"

assert_equal :active_storage_analysis, ActiveStorage.queues[:analysis]
end

test "ActiveStorage.queues[:analysis] is nil by default in 6.1" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "6.1"'

app "development"

assert_nil ActiveStorage.queues[:analysis]
end

test "ActiveStorage.queues[:analysis] is nil without Rails 6 defaults" do
remove_from_config '.*config\.load_defaults.*\n'

Expand All @@ -2463,12 +2498,24 @@ class ::DummySerializer < ActiveJob::Serializers::ObjectSerializer; end
assert_nil ActiveStorage.queues[:analysis]
end

test "ActiveStorage.queues[:purge] is :active_storage_purge by default" do
test "ActiveStorage.queues[:purge] is :active_storage_purge by default in 6.0" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "6.0"'

app "development"

assert_equal :active_storage_purge, ActiveStorage.queues[:purge]
end

test "ActiveStorage.queues[:purge] is nil by default in 6.1" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "6.1"'

app "development"

assert_nil ActiveStorage.queues[:purge]
end

test "ActiveStorage.queues[:purge] is nil without Rails 6 defaults" do
remove_from_config '.*config\.load_defaults.*\n'

Expand All @@ -2477,6 +2524,20 @@ class ::DummySerializer < ActiveJob::Serializers::ObjectSerializer; end
assert_nil ActiveStorage.queues[:purge]
end

test "ActiveStorage.queues[:mirror] is nil without Rails 6 defaults" do
remove_from_config '.*config\.load_defaults.*\n'

app "development"

assert_nil ActiveStorage.queues[:mirror]
end

test "ActiveStorage.queues[:mirror] is nil by default" do
app "development"

assert_nil ActiveStorage.queues[:mirror]
end

test "ActionCable.server.config.cable is set when missing configuration for the current environment" do
quietly do
app "missing"
Expand Down Expand Up @@ -2524,12 +2585,24 @@ class MyLogger < ::Logger
assert_equal 14.days, ActionMailbox.incinerate_after
end

test "ActionMailbox.queues[:incineration] is :action_mailbox_incineration by default" do
test "ActionMailbox.queues[:incineration] is :action_mailbox_incineration by default in 6.0" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "6.0"'

app "development"

assert_equal :action_mailbox_incineration, ActionMailbox.queues[:incineration]
end

test "ActionMailbox.queues[:incineration] is nil by default in 6.1" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "6.1"'

app "development"

assert_nil ActionMailbox.queues[:incineration]
end

test "ActionMailbox.queues[:incineration] can be configured" do
add_to_config <<-RUBY
config.action_mailbox.queues.incineration = :another_queue
Expand All @@ -2540,12 +2613,24 @@ class MyLogger < ::Logger
assert_equal :another_queue, ActionMailbox.queues[:incineration]
end

test "ActionMailbox.queues[:routing] is :action_mailbox_routing by default" do
test "ActionMailbox.queues[:routing] is :action_mailbox_routing by default in 6.0" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "6.0"'

app "development"

assert_equal :action_mailbox_routing, ActionMailbox.queues[:routing]
end

test "ActionMailbox.queues[:routing] is nil by default in 6.1" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "6.1"'

app "development"

assert_nil ActionMailbox.queues[:routing]
end

test "ActionMailbox.queues[:routing] can be configured" do
add_to_config <<-RUBY
config.action_mailbox.queues.routing = :another_queue
Expand Down

0 comments on commit 45d1efa

Please sign in to comment.