diff options
author | Prem Sichanugrist <s@sikachu.com> | 2012-04-27 18:00:58 -0400 |
---|---|---|
committer | Prem Sichanugrist <s@sikachu.com> | 2012-04-27 18:22:25 -0400 |
commit | 4531ba74938985bd2343b27d1a30d099d5975b02 (patch) | |
tree | fd2d4c6f7ef6446639c7e2655f98c11cca7d05b4 | |
parent | 90e90d61cbf89aff779062cc819f2e5e71eb0f5c (diff) | |
download | rails-4531ba74938985bd2343b27d1a30d099d5975b02.tar.gz rails-4531ba74938985bd2343b27d1a30d099d5975b02.tar.bz2 rails-4531ba74938985bd2343b27d1a30d099d5975b02.zip |
Log the exception from the ThreadConsumer
This will make sure you know when there's an exception occur.
-rw-r--r-- | railties/lib/rails/queueing.rb | 6 | ||||
-rw-r--r-- | railties/test/queueing/threaded_consumer_test.rb | 16 |
2 files changed, 21 insertions, 1 deletions
diff --git a/railties/lib/rails/queueing.rb b/railties/lib/rails/queueing.rb index 516447315f..fb5519f827 100644 --- a/railties/lib/rails/queueing.rb +++ b/railties/lib/rails/queueing.rb @@ -34,7 +34,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 |