diff options
author | Douwe Maan <douwe@selenight.nl> | 2014-06-09 18:49:14 +0200 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2014-06-10 17:08:45 +0200 |
commit | da6a86f875199cf28872d9db06efb5c6908ee457 (patch) | |
tree | 6468221265a8f5d3560c3dd182997657b712810d | |
parent | 694b562080a7b1473d20c743877481e13d51c421 (diff) | |
download | rails-da6a86f875199cf28872d9db06efb5c6908ee457.tar.gz rails-da6a86f875199cf28872d9db06efb5c6908ee457.tar.bz2 rails-da6a86f875199cf28872d9db06efb5c6908ee457.zip |
Have .queue_as only set queue name for job in question.
-rw-r--r-- | lib/active_job/base.rb | 2 | ||||
-rw-r--r-- | lib/active_job/queue_name.rb | 16 | ||||
-rw-r--r-- | test/cases/queue_naming_test.rb | 6 |
3 files changed, 18 insertions, 6 deletions
diff --git a/lib/active_job/base.rb b/lib/active_job/base.rb index 0c772e3126..d5ba253016 100644 --- a/lib/active_job/base.rb +++ b/lib/active_job/base.rb @@ -9,8 +9,8 @@ require 'active_job/logging' module ActiveJob class Base extend QueueAdapter - extend QueueName + include QueueName include Enqueuing include Execution include Callbacks diff --git a/lib/active_job/queue_name.rb b/lib/active_job/queue_name.rb index a606b67370..859ddad034 100644 --- a/lib/active_job/queue_name.rb +++ b/lib/active_job/queue_name.rb @@ -1,10 +1,18 @@ module ActiveJob module QueueName - mattr_accessor(:queue_base_name) { "active_jobs" } - mattr_accessor(:queue_name) { queue_base_name } + extend ActiveSupport::Concern - def queue_as(part_name) - self.queue_name = "#{queue_base_name}_#{part_name}" + module ClassMethods + mattr_accessor(:queue_base_name) { "active_jobs" } + + def queue_as(part_name) + self.queue_name = "#{queue_base_name}_#{part_name}" + end + end + + included do + class_attribute :queue_name + self.queue_name = queue_base_name end end end
\ No newline at end of file diff --git a/test/cases/queue_naming_test.rb b/test/cases/queue_naming_test.rb index e171474686..852643b9f6 100644 --- a/test/cases/queue_naming_test.rb +++ b/test/cases/queue_naming_test.rb @@ -9,9 +9,13 @@ class QueueNamingTest < ActiveSupport::TestCase test 'name appended in job' do begin HelloJob.queue_as :greetings + LoggingJob.queue_as :bookkeeping + + assert_equal "active_jobs", NestedJob.queue_name assert_equal "active_jobs_greetings", HelloJob.queue_name + assert_equal "active_jobs_bookkeeping", LoggingJob.queue_name ensure - HelloJob.queue_name = HelloJob.queue_base_name + HelloJob.queue_name = LoggingJob.queue_name = ActiveJob::Base.queue_base_name end end end |