mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove the queue container. Premature consolidation. Set up and maintain queues in the classes that use them instead.
This commit is contained in:
parent
32b4d46484
commit
775829869e
5 changed files with 9 additions and 68 deletions
|
@ -56,32 +56,6 @@ module ActiveSupport
|
|||
end
|
||||
end
|
||||
|
||||
# A container for multiple queues. This class delegates to a default Queue
|
||||
# so that <tt>Rails.queue.push</tt> and friends will Just Work. To use this class
|
||||
# with multiple queues:
|
||||
#
|
||||
# # In your configuration:
|
||||
# Rails.queue[:image_queue] = SomeQueue.new
|
||||
# Rails.queue[:mail_queue] = SomeQueue.new
|
||||
#
|
||||
# # In your app code:
|
||||
# Rails.queue[:mail_queue].push SomeJob.new
|
||||
#
|
||||
class QueueContainer < DelegateClass(::Queue)
|
||||
def initialize(default_queue)
|
||||
@queues = { :default => default_queue }
|
||||
super(default_queue)
|
||||
end
|
||||
|
||||
def [](queue_name)
|
||||
@queues[queue_name]
|
||||
end
|
||||
|
||||
def []=(queue_name, queue)
|
||||
@queues[queue_name] = queue
|
||||
end
|
||||
end
|
||||
|
||||
# The threaded consumer will run jobs in a background thread in
|
||||
# development mode or in a VM where running jobs on a thread in
|
||||
# production mode makes sense.
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
require 'abstract_unit'
|
||||
require 'active_support/queueing'
|
||||
|
||||
module ActiveSupport
|
||||
class ContainerTest < ActiveSupport::TestCase
|
||||
def test_delegates_to_default
|
||||
q = Queue.new
|
||||
container = QueueContainer.new q
|
||||
job = Object.new
|
||||
|
||||
container.push job
|
||||
assert_equal job, q.pop
|
||||
end
|
||||
|
||||
def test_access_default
|
||||
q = Queue.new
|
||||
container = QueueContainer.new q
|
||||
assert_equal q, container[:default]
|
||||
end
|
||||
|
||||
def test_assign_queue
|
||||
container = QueueContainer.new Object.new
|
||||
q = Object.new
|
||||
container[:foo] = q
|
||||
assert_equal q, container[:foo]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -198,11 +198,7 @@ module Rails
|
|||
end
|
||||
|
||||
def queue #:nodoc:
|
||||
@queue ||= ActiveSupport::QueueContainer.new(build_queue)
|
||||
end
|
||||
|
||||
def build_queue #:nodoc:
|
||||
config.queue.new
|
||||
@queue ||= config.queue || ActiveSupport::Queue.new
|
||||
end
|
||||
|
||||
def to_app #:nodoc:
|
||||
|
|
|
@ -52,14 +52,13 @@ module ApplicationTests
|
|||
|
||||
test "uses the default queue for ActionMailer" do
|
||||
require "#{app_path}/config/environment"
|
||||
assert_kind_of ActiveSupport::QueueContainer, ActionMailer::Base.queue
|
||||
assert_kind_of ActiveSupport::Queue, ActionMailer::Base.queue
|
||||
end
|
||||
|
||||
test "allows me to configure queue for ActionMailer" do
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
AppTemplate::Application.configure do
|
||||
Rails.queue[:mailer] = ActiveSupport::TestQueue.new
|
||||
config.action_mailer.queue = Rails.queue[:mailer]
|
||||
config.action_mailer.queue = ActiveSupport::TestQueue.new
|
||||
end
|
||||
RUBY
|
||||
|
||||
|
|
|
@ -19,14 +19,14 @@ module ApplicationTests
|
|||
|
||||
test "the queue is a SynchronousQueue in test mode" do
|
||||
app("test")
|
||||
assert_kind_of ActiveSupport::SynchronousQueue, Rails.application.queue[:default]
|
||||
assert_kind_of ActiveSupport::SynchronousQueue, Rails.queue[:default]
|
||||
assert_kind_of ActiveSupport::SynchronousQueue, Rails.application.queue
|
||||
assert_kind_of ActiveSupport::SynchronousQueue, Rails.queue
|
||||
end
|
||||
|
||||
test "the queue is a SynchronousQueue in development mode" do
|
||||
app("development")
|
||||
assert_kind_of ActiveSupport::SynchronousQueue, Rails.application.queue[:default]
|
||||
assert_kind_of ActiveSupport::SynchronousQueue, Rails.queue[:default]
|
||||
assert_kind_of ActiveSupport::SynchronousQueue, Rails.application.queue
|
||||
assert_kind_of ActiveSupport::SynchronousQueue, Rails.queue
|
||||
end
|
||||
|
||||
class ThreadTrackingJob
|
||||
|
@ -79,7 +79,7 @@ module ApplicationTests
|
|||
def setup_custom_queue
|
||||
add_to_env_config "production", <<-RUBY
|
||||
require "my_queue"
|
||||
config.queue = MyQueue
|
||||
config.queue = MyQueue.new
|
||||
RUBY
|
||||
|
||||
app_file "lib/my_queue.rb", <<-RUBY
|
||||
|
@ -96,7 +96,7 @@ module ApplicationTests
|
|||
test "a custom queue implementation can be provided" do
|
||||
setup_custom_queue
|
||||
|
||||
assert_kind_of MyQueue, Rails.queue[:default]
|
||||
assert_kind_of MyQueue, Rails.queue
|
||||
|
||||
job = Struct.new(:id, :ran) do
|
||||
def run
|
||||
|
|
Loading…
Reference in a new issue