aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-04-27 15:24:14 -0700
committerJosé Valim <jose.valim@gmail.com>2012-04-27 15:24:14 -0700
commitd8c3ad73dd85d9e429264a9f43f8cca51f852275 (patch)
tree399724742a576eaa71250517a543406ad1d9b7bf
parent3fc16a99dabefd79f4a09f0338e6b904968578e9 (diff)
parent4531ba74938985bd2343b27d1a30d099d5975b02 (diff)
downloadrails-d8c3ad73dd85d9e429264a9f43f8cca51f852275.tar.gz
rails-d8c3ad73dd85d9e429264a9f43f8cca51f852275.tar.bz2
rails-d8c3ad73dd85d9e429264a9f43f8cca51f852275.zip
Merge pull request #6021 from sikachu/log_exception
Log the exception from the ThreadConsumer
-rw-r--r--railties/lib/rails/queueing.rb6
-rw-r--r--railties/test/queueing/threaded_consumer_test.rb16
2 files changed, 21 insertions, 1 deletions
diff --git a/railties/lib/rails/queueing.rb b/railties/lib/rails/queueing.rb
index 9ba55c0109..81cc12b7aa 100644
--- a/railties/lib/rails/queueing.rb
+++ b/railties/lib/rails/queueing.rb
@@ -42,7 +42,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
diff --git a/railties/test/queueing/threaded_consumer_test.rb b/railties/test/queueing/threaded_consumer_test.rb
index d00a67d511..8e31ebf3c7 100644
--- a/railties/test/queueing/threaded_consumer_test.rb
+++ b/railties/test/queueing/threaded_consumer_test.rb
@@ -62,4 +62,20 @@ class TestThreadConsumer < ActiveSupport::TestCase
assert_equal true, ran
end
+
+ test "log job that raises an exception" do
+ require "active_support/log_subscriber/test_helper"
+ logger = ActiveSupport::LogSubscriber::TestHelper::MockLogger.new
+ Rails.logger = logger
+
+ job = Job.new(1) do
+ raise "RuntimeError: Error!"
+ end
+
+ @queue.push job
+ sleep 0.1
+
+ assert_equal 1, logger.logged(:error).size
+ assert_match /Job Error: RuntimeError: Error!/, logger.logged(:error).last
+ end
end