aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2012-10-12 20:45:54 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2012-10-12 22:27:41 -0700
commitc8fe0d58bcc7deb49711606566c854bf0ed7f107 (patch)
tree49f8c2b9780f58117282eff2d86e0b08cd9065bf
parent1dc2ea8f3dfc1cce1958bd661c641ed345adf910 (diff)
downloadrails-c8fe0d58bcc7deb49711606566c854bf0ed7f107.tar.gz
rails-c8fe0d58bcc7deb49711606566c854bf0ed7f107.tar.bz2
rails-c8fe0d58bcc7deb49711606566c854bf0ed7f107.zip
Backpedal from class-oriented config.queue. Set an actual queue instance.
-rw-r--r--activesupport/lib/active_support/queueing.rb4
-rw-r--r--guides/source/4_0_release_notes.md4
-rw-r--r--guides/source/configuring.md4
-rw-r--r--railties/CHANGELOG.md4
-rw-r--r--railties/lib/rails/application/configuration.rb2
-rw-r--r--railties/lib/rails/application/finisher.rb4
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt2
-rw-r--r--railties/test/application/configuration_test.rb8
-rw-r--r--railties/test/application/queue_test.rb6
10 files changed, 14 insertions, 26 deletions
diff --git a/activesupport/lib/active_support/queueing.rb b/activesupport/lib/active_support/queueing.rb
index 430ecbe323..c8ba28021d 100644
--- a/activesupport/lib/active_support/queueing.rb
+++ b/activesupport/lib/active_support/queueing.rb
@@ -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]
diff --git a/guides/source/4_0_release_notes.md b/guides/source/4_0_release_notes.md
index 54fe49252f..c909ef1496 100644
--- a/guides/source/4_0_release_notes.md
+++ b/guides/source/4_0_release_notes.md
@@ -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`.
diff --git a/guides/source/configuring.md b/guides/source/configuring.md
index 2131a6c6a8..26c7976c6b 100644
--- a/guides/source/configuring.md
+++ b/guides/source/configuring.md
@@ -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.
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index 2ecdfdcb22..ba9b24c6c6 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -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*
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index a7a35c2685..2bcdb3d502 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -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
diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb
index d2a402aa51..26fca503a0 100644
--- a/railties/lib/rails/application/finisher.rb
+++ b/railties/lib/rails/application/finisher.rb
@@ -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
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
index 74457b0efd..8aaaba628c 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
@@ -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
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt
index fe2820f64e..a5ef0cd9cd 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt
@@ -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
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 07d47dc67b..3691c5e3d5 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -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"
diff --git a/railties/test/application/queue_test.rb b/railties/test/application/queue_test.rb
index 080678f2d5..b4c9a31185 100644
--- a/railties/test/application/queue_test.rb
+++ b/railties/test/application/queue_test.rb
@@ -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