mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
ActiveJob: Reworked queue_base_name as default_queue_name + Allow configure ActiveJob from app.config.active_job
This commit is contained in:
parent
e034ac33ea
commit
94ae25ecd5
4 changed files with 23 additions and 11 deletions
|
@ -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
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue