From 94ae25ecd5635f7f97a2e53afa8e3f82c408435d Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Fri, 15 Aug 2014 23:32:08 +0300 Subject: [PATCH] ActiveJob: Reworked queue_base_name as default_queue_name + Allow configure ActiveJob from app.config.active_job --- activejob/lib/active_job/queue_name.rb | 8 ++++---- activejob/lib/active_job/railtie.rb | 14 +++++++++++++- activejob/test/cases/queue_naming_test.rb | 10 +++++----- guides/source/active_job_basics.md | 2 +- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/activejob/lib/active_job/queue_name.rb b/activejob/lib/active_job/queue_name.rb index 859ddad034..c2186d9fe9 100644 --- a/activejob/lib/active_job/queue_name.rb +++ b/activejob/lib/active_job/queue_name.rb @@ -3,16 +3,16 @@ module ActiveJob extend ActiveSupport::Concern module ClassMethods - mattr_accessor(:queue_base_name) { "active_jobs" } + mattr_accessor(:default_queue_name) { "default" } def queue_as(part_name) - self.queue_name = "#{queue_base_name}_#{part_name}" + self.queue_name = part_name.to_s.presence || default_queue_name end end included do class_attribute :queue_name - self.queue_name = queue_base_name + self.queue_name = default_queue_name end end -end \ No newline at end of file +end diff --git a/activejob/lib/active_job/railtie.rb b/activejob/lib/active_job/railtie.rb index 16736374af..7c1dd8f275 100644 --- a/activejob/lib/active_job/railtie.rb +++ b/activejob/lib/active_job/railtie.rb @@ -4,8 +4,20 @@ require 'rails' module ActiveJob # = Active Job Railtie class Railtie < Rails::Railtie # :nodoc: - initializer 'active_job' do + config.active_job = ActiveSupport::OrderedOptions.new + + initializer 'active_job.logger' do ActiveSupport.on_load(:active_job) { self.logger = ::Rails.logger } end + + initializer "active_job.set_configs" do |app| + options = app.config.active_job + options.queue_adapter ||= :inline + + ActiveSupport.on_load(:active_job) do + options.each { |k,v| send("#{k}=", v) } + end + end + end end diff --git a/activejob/test/cases/queue_naming_test.rb b/activejob/test/cases/queue_naming_test.rb index 7cb516bbb4..426af608f0 100644 --- a/activejob/test/cases/queue_naming_test.rb +++ b/activejob/test/cases/queue_naming_test.rb @@ -5,7 +5,7 @@ require 'jobs/nested_job' class QueueNamingTest < ActiveSupport::TestCase test 'name derived from base' do - assert_equal "active_jobs", HelloJob.queue_name + assert_equal "default", HelloJob.queue_name end test 'name appended in job' do @@ -13,11 +13,11 @@ class QueueNamingTest < ActiveSupport::TestCase 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 + assert_equal "default", NestedJob.queue_name + assert_equal "greetings", HelloJob.queue_name + assert_equal "bookkeeping", LoggingJob.queue_name ensure - HelloJob.queue_name = LoggingJob.queue_name = ActiveJob::Base.queue_base_name + HelloJob.queue_name = LoggingJob.queue_name = ActiveJob::Base.default_queue_name end end end diff --git a/guides/source/active_job_basics.md b/guides/source/active_job_basics.md index 4442753370..c100448a48 100644 --- a/guides/source/active_job_basics.md +++ b/guides/source/active_job_basics.md @@ -224,7 +224,7 @@ You can easy change your adapter: ```ruby # be sure to have the adapter gem in your Gemfile and follow the adapter specific # installation and deployment instructions -YourApp::Application.config.active_job.adapter = :sidekiq +YourApp::Application.config.active_job.queue_adapter = :sidekiq ``` Queues