diff options
author | Daniel Colson <danieljamescolson@gmail.com> | 2018-11-03 22:39:18 -0400 |
---|---|---|
committer | Daniel Colson <danieljamescolson@gmail.com> | 2018-11-03 22:39:18 -0400 |
commit | b517347be1e229554093b061bd3fd7dbf9017f6a (patch) | |
tree | e2482010ad0ab83316f2ae55010c4c23bacbc856 /activejob/test/cases | |
parent | caad9e1080e5b98bc8b3c40c0f2d226a3a9e859a (diff) | |
download | rails-b517347be1e229554093b061bd3fd7dbf9017f6a.tar.gz rails-b517347be1e229554093b061bd3fd7dbf9017f6a.tar.bz2 rails-b517347be1e229554093b061bd3fd7dbf9017f6a.zip |
Allow using queue prefix with a default queue name
Fixes #34366
Currently setting queue_name_prefix will not combine a prefix with the
default_queue_name; it will only affect queue names set with `queue_as`.
With this PR the prefix will affect the default_queue_name as well.
Closes #19831
Currently setting default_queue_name doesn't actually affect the
queue_name default (although default_queue_name does get used if you
pass a falsey `part_name` to `queue_as`). This PR would get
default_queue_name working as expected as well.
Because the queue_name default is now a lambda wrapping the
default_queue_name, rather than the default_queue_name itself, I had to
update one test to use the instance method `#queue_name` (which
`instance_exec`s the value) instead of the class method. I think this
change is OK, since only the instance method is documented.
There was a question about whether we want a `default_queue_name`
configuration. If we want to get rid of it, I would also be happy to
open a PR for that instead. It has been around for a while now, but it
also hasn't really worked for a while now.
r? @matthewd
since you had an opinion about this before
Diffstat (limited to 'activejob/test/cases')
-rw-r--r-- | activejob/test/cases/queue_naming_test.rb | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/activejob/test/cases/queue_naming_test.rb b/activejob/test/cases/queue_naming_test.rb index b64a38f91e..4b43c7c3c5 100644 --- a/activejob/test/cases/queue_naming_test.rb +++ b/activejob/test/cases/queue_naming_test.rb @@ -7,7 +7,7 @@ require "jobs/nested_job" class QueueNamingTest < ActiveSupport::TestCase test "name derived from base" do - assert_equal "default", HelloJob.queue_name + assert_equal "default", HelloJob.new.queue_name end test "uses given queue name job" do @@ -97,6 +97,33 @@ class QueueNamingTest < ActiveSupport::TestCase end end + test "using a custom default_queue_name" do + original_default_queue_name = ActiveJob::Base.default_queue_name + + begin + ActiveJob::Base.default_queue_name = "default_queue_name" + + assert_equal "default_queue_name", HelloJob.new.queue_name + ensure + ActiveJob::Base.default_queue_name = original_default_queue_name + end + end + + test "queue_name_prefix prepended to the default_queue_name" do + original_queue_name_prefix = ActiveJob::Base.queue_name_prefix + original_default_queue_name = ActiveJob::Base.default_queue_name + + begin + ActiveJob::Base.queue_name_prefix = "prefix" + ActiveJob::Base.default_queue_name = "default_queue_name" + + assert_equal "prefix_default_queue_name", HelloJob.new.queue_name + ensure + ActiveJob::Base.queue_name_prefix = original_queue_name_prefix + ActiveJob::Base.default_queue_name = original_default_queue_name + end + end + test "uses queue passed to #set" do job = HelloJob.set(queue: :some_queue).perform_later assert_equal "some_queue", job.queue_name |