diff options
Diffstat (limited to 'activejob')
-rw-r--r-- | activejob/lib/active_job/queue_name.rb | 5 | ||||
-rw-r--r-- | activejob/test/cases/queue_naming_test.rb | 15 |
2 files changed, 19 insertions, 1 deletions
diff --git a/activejob/lib/active_job/queue_name.rb b/activejob/lib/active_job/queue_name.rb index c2186d9fe9..9698835b6e 100644 --- a/activejob/lib/active_job/queue_name.rb +++ b/activejob/lib/active_job/queue_name.rb @@ -3,10 +3,13 @@ module ActiveJob extend ActiveSupport::Concern module ClassMethods + mattr_accessor(:queue_name_prefix) mattr_accessor(:default_queue_name) { "default" } def queue_as(part_name) - self.queue_name = part_name.to_s.presence || default_queue_name + queue_name = part_name.to_s.presence || default_queue_name + name_parts = [queue_name_prefix.presence, queue_name] + self.queue_name = name_parts.compact.join('_') end end diff --git a/activejob/test/cases/queue_naming_test.rb b/activejob/test/cases/queue_naming_test.rb index 426af608f0..fdfd1afceb 100644 --- a/activejob/test/cases/queue_naming_test.rb +++ b/activejob/test/cases/queue_naming_test.rb @@ -20,4 +20,19 @@ class QueueNamingTest < ActiveSupport::TestCase HelloJob.queue_name = LoggingJob.queue_name = ActiveJob::Base.default_queue_name end end + + test 'should prefix the queue name' do + begin + original_queue_name_prefix = ActiveJob::Base.queue_name_prefix + original_queue_name = HelloJob.queue_name + + ActiveJob::Base.queue_name_prefix = 'aj' + HelloJob.queue_as :low + assert_equal 'aj_low', HelloJob.queue_name + ensure + ActiveJob::Base.queue_name_prefix = original_queue_name_prefix + HelloJob.queue_name = original_queue_name + end + end + end |