aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails')
-rw-r--r--railties/lib/rails/application.rb6
-rw-r--r--railties/lib/rails/application/configuration.rb2
-rw-r--r--railties/lib/rails/application/finisher.rb2
-rw-r--r--railties/lib/rails/configuration.rb2
-rw-r--r--railties/lib/rails/engine.rb8
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt2
-rw-r--r--railties/lib/rails/generators/test_case.rb8
-rw-r--r--railties/lib/rails/paths.rb2
-rw-r--r--railties/lib/rails/queueing.rb40
10 files changed, 42 insertions, 32 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 6ab448910e..1680a6ed00 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -200,7 +200,11 @@ module Rails
end
def queue #:nodoc:
- @queue ||= config.queue.new
+ @queue ||= build_queue
+ end
+
+ def build_queue # :nodoc:
+ config.queue.new
end
def to_app
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index a36dad0e98..25bb680f69 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -43,7 +43,7 @@ module Rails
@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
diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb
index 6475b381f4..6a24e01f29 100644
--- a/railties/lib/rails/application/finisher.rb
+++ b/railties/lib/rails/application/finisher.rb
@@ -95,7 +95,7 @@ module Rails
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
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb
index d8ca6cbd21..493eacdc5a 100644
--- a/railties/lib/rails/configuration.rb
+++ b/railties/lib/rails/configuration.rb
@@ -16,7 +16,7 @@ module Rails
#
# config.middleware.use Magical::Unicorns
#
- # This will put the +Magical::Unicorns+ middleware on the end of the stack.
+ # This will put the <tt>Magical::Unicorns</tt> middleware on the end of the stack.
# You can use +insert_before+ if you wish to add a middleware before another:
#
# config.middleware.insert_before ActionDispatch::Head, Magical::Unicorns
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index 5d99b820c9..d4f632702c 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -486,8 +486,10 @@ module Rails
end
def routes
- @routes ||= ActionDispatch::Routing::RouteSet.new
- @routes.draw_paths.concat paths["config/routes"].paths
+ @routes ||= ActionDispatch::Routing::RouteSet.new.tap do |routes|
+ routes.draw_paths.concat paths["config/routes"].paths
+ end
+
@routes.append(&Proc.new) if block_given?
@routes
end
@@ -619,7 +621,7 @@ module Rails
end
def routes?
- defined?(@routes)
+ defined?(@routes) && @routes
end
def has_migrations?
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
index c486ae590e..24bcec854c 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
+++ b/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
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
index 854e6e95cd..072aa8355d 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
+++ b/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
diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb
index 2cb34fab7a..508e221c60 100644
--- a/railties/lib/rails/generators/test_case.rb
+++ b/railties/lib/rails/generators/test_case.rb
@@ -79,8 +79,8 @@ module Rails
#
# Finally, when a block is given, it yields the file content:
#
- # assert_file "app/controller/products_controller.rb" do |controller|
- # assert_instance_method :index, content do |index|
+ # assert_file "app/controllers/products_controller.rb" do |controller|
+ # assert_instance_method :index, controller do |index|
# assert_match(/Product\.all/, index)
# end
# end
@@ -159,8 +159,8 @@ module Rails
# Asserts the given method exists in the given content. When a block is given,
# it yields the content of the method.
#
- # assert_file "app/controller/products_controller.rb" do |controller|
- # assert_instance_method :index, content do |index|
+ # assert_file "app/controllers/products_controller.rb" do |controller|
+ # assert_instance_method :index, controller do |index|
# assert_match(/Product\.all/, index)
# end
# end
diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb
index fced6f8896..b787d91821 100644
--- a/railties/lib/rails/paths.rb
+++ b/railties/lib/rails/paths.rb
@@ -10,7 +10,7 @@ module Rails
# root.add "app/controllers", :eager_load => true
#
# The command above creates a new root object and add "app/controllers" as a path.
- # This means we can get a +Rails::Paths::Path+ object back like below:
+ # This means we can get a <tt>Rails::Paths::Path</tt> object back like below:
#
# path = root["app/controllers"]
# path.eager_load? # => true
diff --git a/railties/lib/rails/queueing.rb b/railties/lib/rails/queueing.rb
index b77940f821..2e187b8555 100644
--- a/railties/lib/rails/queueing.rb
+++ b/railties/lib/rails/queueing.rb
@@ -1,33 +1,33 @@
+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 +contents+
+ # can be made about its contents. The test queue provides a +jobs+
# method to make assertions about the queue's contents and a +drain+
# method to drain the queue and run the jobs.
#
# Jobs are run in a separate thread to catch mistakes where code
# assumes that the job is run in the same thread.
- class TestQueue
- attr_reader :contents
-
- def initialize
- @contents = []
+ class TestQueue < ::Queue
+ # Get a list of the jobs off this queue. This method may not be
+ # available on production queues.
+ def jobs
+ @que.dup
end
+ # Drain the queue, running all jobs in a different thread. This method
+ # may not be available on production queues.
def drain
# run the jobs in a separate thread so assumptions of synchronous
# jobs are caught in test mode.
- t = Thread.new do
- while job = @contents.pop
- job.run
- end
- end
- t.join
- end
-
- # implement the Queue API
- def push(object)
- @contents << object
+ Thread.new { pop.run until empty? }.join
end
end
@@ -50,7 +50,11 @@ module Rails
def start
@thread = Thread.new do
while job = @queue.pop
- job.run
+ begin
+ job.run
+ rescue Exception => e
+ Rails.logger.error "Job Error: #{e.message}\n#{e.backtrace.join("\n")}"
+ end
end
end
self