Skip to content
Permalink
Browse files

Remove the queue container. Premature consolidation. Set up and maint…

…ain queues in the classes that use them instead.
  • Loading branch information...
jeremy committed Oct 13, 2012
1 parent 32b4d46 commit 775829869e23666e114edbe8d6d3ff08d5d71025
@@ -56,32 +56,6 @@ def push(job)
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.

This file was deleted.

@@ -198,11 +198,7 @@ def config #:nodoc:
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 @@ def teardown

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 @@ def app_const

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 @@ def ran?
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 @@ def push(job)
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

0 comments on commit 7758298

Please sign in to comment.
You can’t perform that action at this time.