mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Backpedal from class-oriented config.queue. Set an actual queue instance.
This commit is contained in:
parent
1dc2ea8f3d
commit
c8fe0d58bc
10 changed files with 14 additions and 26 deletions
|
@ -64,10 +64,6 @@ module ActiveSupport
|
|||
# queue and joins the thread, which will ensure that all jobs
|
||||
# are executed before the process finally dies.
|
||||
class ThreadedQueueConsumer
|
||||
def self.start(*args)
|
||||
new(*args).start
|
||||
end
|
||||
|
||||
def initialize(queue, options = {})
|
||||
@queue = queue
|
||||
@logger = options[:logger]
|
||||
|
|
|
@ -95,9 +95,9 @@ Railties
|
|||
|
||||
* Load all environments available in `config.paths["config/environments"]`.
|
||||
|
||||
* Add `config.queue_consumer` to allow the default consumer to be configurable.
|
||||
* Add `config.queue_consumer` to change the job queue consumer from the default `ActiveSupport::ThreadedQueueConsumer`.
|
||||
|
||||
* Add `Rails.queue` as an interface with a default implementation that consumes jobs in a separate thread.
|
||||
* Add `Rails.queue` for processing jobs in the background.
|
||||
|
||||
* Remove `Rack::SSL` in favour of `ActionDispatch::SSL`.
|
||||
|
||||
|
|
|
@ -115,9 +115,9 @@ NOTE. The `config.asset_path` configuration is ignored if the asset pipeline is
|
|||
|
||||
* `config.middleware` allows you to configure the application's middleware. This is covered in depth in the [Configuring Middleware](#configuring-middleware) section below.
|
||||
|
||||
* `config.queue` configures a different queue implementation for the application. Defaults to `ActiveSupport::SynchronousQueue`. Note that, if the default queue is changed, the default `queue_consumer` is not going to be initialized, it is up to the new queue implementation to handle starting and shutting down its own consumer(s).
|
||||
* `config.queue` configures the default job queue for the application. Defaults to `ActiveSupport::Queue.new` which processes jobs in a background thread. If you change the queue, you're responsible for running the jobs as well.
|
||||
|
||||
* `config.queue_consumer` configures a different consumer implementation for the default queue. Defaults to `ActiveSupport::ThreadedQueueConsumer`.
|
||||
* `config.queue_consumer` configures a different job consumer for the default queue. Defaults to `ActiveSupport::ThreadedQueueConsumer`. The job consumer must respond to `start`.
|
||||
|
||||
* `config.reload_classes_only_on_change` enables or disables reloading of classes only when tracked files change. By default tracks everything on autoload paths and is set to true. If `config.cache_classes` is true, this option is ignored.
|
||||
|
||||
|
|
|
@ -81,9 +81,9 @@
|
|||
|
||||
* Load all environments available in `config.paths["config/environments"]`. *Piotr Sarnacki*
|
||||
|
||||
* Add `config.queue_consumer` to allow the default consumer to be configurable. *Carlos Antonio da Silva*
|
||||
* Add `config.queue_consumer` to change the job queue consumer from the default `ActiveSupport::ThreadedQueueConsumer`. *Carlos Antonio da Silva*
|
||||
|
||||
* Add Rails.queue as an interface with a default implementation that consumes jobs in a separate thread. *Yehuda Katz*
|
||||
* Add `Rails.queue` for processing jobs in the background. *Yehuda Katz*
|
||||
|
||||
* Remove Rack::SSL in favour of ActionDispatch::SSL. *Rafael Mendonça França*
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ module Rails
|
|||
@exceptions_app = nil
|
||||
@autoflush_log = true
|
||||
@log_formatter = ActiveSupport::Logger::SimpleFormatter.new
|
||||
@queue = ActiveSupport::SynchronousQueue
|
||||
@queue = ActiveSupport::SynchronousQueue.new
|
||||
@queue_consumer = ActiveSupport::ThreadedQueueConsumer
|
||||
@eager_load = nil
|
||||
|
||||
|
|
|
@ -97,8 +97,8 @@ module Rails
|
|||
end
|
||||
|
||||
initializer :activate_queue_consumer do |app|
|
||||
if config.queue == ActiveSupport::Queue
|
||||
app.queue_consumer = config.queue_consumer.start(app.queue, {logger: Rails.logger})
|
||||
if config.queue.class == ActiveSupport::Queue
|
||||
app.queue_consumer = config.queue_consumer.start
|
||||
at_exit { app.queue_consumer.shutdown }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -88,5 +88,5 @@
|
|||
|
||||
# Default the production mode queue to an synchronous queue. You will probably
|
||||
# want to replace this with an out-of-process queueing solution.
|
||||
# config.queue = ActiveSupport::SynchronousQueue
|
||||
# config.queue = ActiveSupport::SynchronousQueue.new
|
||||
end
|
||||
|
|
|
@ -35,5 +35,5 @@
|
|||
config.active_support.deprecation = :stderr
|
||||
|
||||
# Use the synchronous queue to run jobs immediately.
|
||||
config.queue = ActiveSupport::SynchronousQueue
|
||||
config.queue = ActiveSupport::SynchronousQueue.new
|
||||
end
|
||||
|
|
|
@ -56,14 +56,6 @@ module ApplicationTests
|
|||
assert_match "ActiveRecord::PendingMigrationError", last_response.body
|
||||
end
|
||||
|
||||
test "multiple queue construction is possible" do
|
||||
require 'rails'
|
||||
require "#{app_path}/config/environment"
|
||||
mail_queue = Rails.application.build_queue
|
||||
image_processing_queue = Rails.application.build_queue
|
||||
assert_not_equal mail_queue, image_processing_queue
|
||||
end
|
||||
|
||||
test "Rails.groups returns available groups" do
|
||||
require "rails"
|
||||
|
||||
|
|
|
@ -113,12 +113,12 @@ module ApplicationTests
|
|||
test "a custom consumer implementation can be provided" do
|
||||
add_to_env_config "production", <<-RUBY
|
||||
require "my_queue_consumer"
|
||||
config.queue = ActiveSupport::Queue
|
||||
config.queue_consumer = MyQueueConsumer
|
||||
config.queue = ActiveSupport::Queue.new
|
||||
config.queue_consumer = MyQueueConsumer.new
|
||||
RUBY
|
||||
|
||||
app_file "lib/my_queue_consumer.rb", <<-RUBY
|
||||
class MyQueueConsumer < ActiveSupport::ThreadedQueueConsumer
|
||||
class MyQueueConsumer
|
||||
attr_reader :started
|
||||
|
||||
def start
|
||||
|
|
Loading…
Reference in a new issue