diff options
author | Terry Meacham <zv1n.fire@gmail.com> | 2014-09-23 15:51:44 -0500 |
---|---|---|
committer | Terry Meacham <zv1n.fire@gmail.com> | 2014-10-26 21:46:05 -0500 |
commit | 11ab04b11170253e96515c3ada6f2566b092533a (patch) | |
tree | ce22987d118a311aef27a734357314b9994f58ef /activejob | |
parent | 85faea4b8320e728854838c6da97c9435de8869e (diff) | |
download | rails-11ab04b11170253e96515c3ada6f2566b092533a.tar.gz rails-11ab04b11170253e96515c3ada6f2566b092533a.tar.bz2 rails-11ab04b11170253e96515c3ada6f2566b092533a.zip |
Added queue_name_delimiter attribute.
- Added ActiveJob::Base#queue_name_delimiter to allow for
developers using ActiveJob to change the delimiter from the default
('_') to whatever else they may be using (e.g., '.', '-', ...).
- Updated source guide to include a blurb about the delimiter.
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 | 19 |
2 files changed, 22 insertions, 2 deletions
diff --git a/activejob/lib/active_job/queue_name.rb b/activejob/lib/active_job/queue_name.rb index d167617e4e..6ee7142ce6 100644 --- a/activejob/lib/active_job/queue_name.rb +++ b/activejob/lib/active_job/queue_name.rb @@ -26,13 +26,16 @@ module ActiveJob def queue_name_from_part(part_name) #:nodoc: queue_name = part_name || default_queue_name name_parts = [queue_name_prefix.presence, queue_name] - name_parts.compact.join('_') + name_parts.compact.join(queue_name_delimiter) end end included do class_attribute :queue_name, instance_accessor: false + class_attribute :queue_name_delimiter, instance_accessor: false + self.queue_name = default_queue_name + self.queue_name_delimiter = '_' # set default delimiter to '_' end # Returns the name of the queue the job will be run on diff --git a/activejob/test/cases/queue_naming_test.rb b/activejob/test/cases/queue_naming_test.rb index 886f41271a..898016a704 100644 --- a/activejob/test/cases/queue_naming_test.rb +++ b/activejob/test/cases/queue_naming_test.rb @@ -64,7 +64,7 @@ class QueueNamingTest < ActiveSupport::TestCase end end - test 'queu_name_prefix prepended to the queue name' do + test 'queue_name_prefix prepended to the queue name with default delimiter' do original_queue_name_prefix = ActiveJob::Base.queue_name_prefix original_queue_name = HelloJob.queue_name @@ -78,6 +78,23 @@ class QueueNamingTest < ActiveSupport::TestCase end end + test 'queue_name_prefix prepended to the queue name with custom delimiter' do + original_queue_name_prefix = ActiveJob::Base.queue_name_prefix + original_queue_name_delimiter = ActiveJob::Base.queue_name_delimiter + original_queue_name = HelloJob.queue_name + + begin + ActiveJob::Base.queue_name_delimiter = '.' + 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 + ActiveJob::Base.queue_name_delimiter = original_queue_name_delimiter + HelloJob.queue_name = original_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 |