diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-07-19 12:09:39 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-07-19 12:09:39 -0700 |
commit | 3b3ca133071419a42c0b1f55c96fc604ff73f2ac (patch) | |
tree | ed88fbf05020aa8ee637a9dff0bcb6cddc2fb223 /railties/lib | |
parent | fa3c84fabee01847c3468cd1e8e32003693bc629 (diff) | |
download | rails-3b3ca133071419a42c0b1f55c96fc604ff73f2ac.tar.gz rails-3b3ca133071419a42c0b1f55c96fc604ff73f2ac.tar.bz2 rails-3b3ca133071419a42c0b1f55c96fc604ff73f2ac.zip |
adding Rails::Queueing::Container
This allows us to do:
In your configuration:
Rails.queue[:image_queue] = SomeQueue.new
Rails.queue[:mail_queue] = SomeQueue.new
In your app code:
Rails.queue[:mail_queue].push MailJob.new
Both jobs pushed to the same default queue
Rails.queue.push DefaultJob.new
Rails.queue[:default].push DefaultJob.new
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/application.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/queueing.rb | 27 |
2 files changed, 28 insertions, 1 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 3afbf0a03e..da5b33c0fb 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -177,7 +177,7 @@ module Rails end def queue #:nodoc: - @queue ||= build_queue + @queue ||= Queueing::Container.new(build_queue) end def build_queue #:nodoc: diff --git a/railties/lib/rails/queueing.rb b/railties/lib/rails/queueing.rb index 8a76914548..892cf8e894 100644 --- a/railties/lib/rails/queueing.rb +++ b/railties/lib/rails/queueing.rb @@ -1,7 +1,34 @@ require "thread" +require 'delegate' module Rails module Queueing + # A container for multiple queues. This class delegates to a default Queue + # so that Rails.queue.push 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 Container < 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 + # A Queue that simply inherits from STDLIB's Queue. Everytime this # queue is used, Rails automatically sets up a ThreadedConsumer # to consume it. |