Skip to content
Browse files

Use Rails::Queueing::Queue instead of Queue so people can build their…

… own consumers around stdlib's Queue
  • Loading branch information...
1 parent fc6b115 commit 9fc9e894771d1915fe3e565305424ed9ca537b79 @josevalim josevalim committed
View
2 railties/lib/rails/application/configuration.rb
@@ -43,7 +43,7 @@ def initialize(*)
@autoflush_log = true
@log_formatter = ActiveSupport::Logger::SimpleFormatter.new
@use_schema_cache_dump = true
- @queue = Queue
+ @queue = Rails::Queueing::Queue
@assets = ActiveSupport::OrderedOptions.new
@assets.enabled = false
View
2 railties/lib/rails/application/finisher.rb
@@ -95,7 +95,7 @@ module Finisher
end
initializer :activate_queue_consumer do |app|
- if config.queue == Queue
+ if config.queue == Rails::Queueing::Queue
consumer = Rails::Queueing::ThreadedConsumer.start(app.queue)
at_exit { consumer.shutdown }
end
View
2 railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
@@ -37,5 +37,5 @@
<%- end -%>
# In development, use an in-memory queue for queueing
- config.queue = Queue
+ config.queue = Rails::Queueing::Queue
end
View
2 railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
@@ -79,5 +79,5 @@
# Default the production mode queue to an in-memory queue. You will probably
# want to replace this with an out-of-process queueing solution
- config.queue = Queue
+ config.queue = Rails::Queueing::Queue
end
View
8 railties/lib/rails/queueing.rb
@@ -1,5 +1,13 @@
+require "thread"
+
module Rails
module Queueing
+ # A Queue that simply inherits from STDLIB's Queue. Everytime this
+ # queue is used, Rails automatically sets up a ThreadedConsumer
+ # to consume it.
+ class Queue < ::Queue
+ end
+
# In test mode, the Rails queue is backed by an Array so that assertions
# can be made about its contents. The test queue provides a +jobs+
# method to make assertions about the queue's contents and a +drain+
View
4 railties/test/application/queue_test.rb
@@ -26,8 +26,8 @@ def app_const
test "the queue is a Queue in development mode" do
app("development")
- assert_kind_of Queue, Rails.application.queue
- assert_kind_of Queue, Rails.queue
+ assert_kind_of Rails::Queueing::Queue, Rails.application.queue
+ assert_kind_of Rails::Queueing::Queue, Rails.queue
end
test "in development mode, an enqueued job will be processed in a separate thread" do
View
2 railties/test/queueing/threaded_consumer_test.rb
@@ -15,7 +15,7 @@ def run
end
def setup
- @queue = Queue.new
+ @queue = Rails::Queueing::Queue.new
@consumer = Rails::Queueing::ThreadedConsumer.start(@queue)
end

0 comments on commit 9fc9e89

Please sign in to comment.
Something went wrong with that request. Please try again.