diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2012-10-13 09:54:34 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2012-10-13 09:54:34 -0700 |
commit | 1fd89260566eae1b8d3531bf83233eb18c27ab3d (patch) | |
tree | 93dd1a755b5f913cf080768136c527b9a262f99f /railties | |
parent | c8fe0d58bcc7deb49711606566c854bf0ed7f107 (diff) | |
download | rails-1fd89260566eae1b8d3531bf83233eb18c27ab3d.tar.gz rails-1fd89260566eae1b8d3531bf83233eb18c27ab3d.tar.bz2 rails-1fd89260566eae1b8d3531bf83233eb18c27ab3d.zip |
Test that a Rails.queue consumer is automatically started in production
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/application/finisher.rb | 3 | ||||
-rw-r--r-- | railties/test/application/queue_test.rb | 12 |
3 files changed, 14 insertions, 3 deletions
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 2bcdb3d502..9b89d7094c 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -44,7 +44,7 @@ module Rails @autoflush_log = true @log_formatter = ActiveSupport::Logger::SimpleFormatter.new @queue = ActiveSupport::SynchronousQueue.new - @queue_consumer = ActiveSupport::ThreadedQueueConsumer + @queue_consumer = nil @eager_load = nil @assets = ActiveSupport::OrderedOptions.new diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 26fca503a0..4a15a36ba9 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -98,7 +98,8 @@ module Rails initializer :activate_queue_consumer do |app| if config.queue.class == ActiveSupport::Queue - app.queue_consumer = config.queue_consumer.start + app.queue_consumer = config.queue_consumer || config.queue.consumer + app.queue_consumer.start at_exit { app.queue_consumer.shutdown } end end diff --git a/railties/test/application/queue_test.rb b/railties/test/application/queue_test.rb index b4c9a31185..b0b3cf18e9 100644 --- a/railties/test/application/queue_test.rb +++ b/railties/test/application/queue_test.rb @@ -69,6 +69,17 @@ module ApplicationTests refute job.ran_in_different_thread?, "Expected job to run in the same thread" end + test "in production, automatically spawn a queue consumer in a background thread" do + add_to_env_config "production", <<-RUBY + config.queue = ActiveSupport::Queue.new + RUBY + + app("production") + + assert_nil Rails.application.config.queue_consumer + assert_kind_of ActiveSupport::ThreadedQueueConsumer, Rails.application.queue_consumer + end + test "attempting to marshal a queue will raise an exception" do app("test") assert_raises TypeError do @@ -123,7 +134,6 @@ module ApplicationTests def start @started = true - self end end RUBY |