diff options
Diffstat (limited to 'railties')
-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 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 |