Browse files

Merge pull request #6021 from sikachu/log_exception

Log the exception from the ThreadConsumer
  • Loading branch information...
2 parents 3fc16a9 + 4531ba7 commit d8c3ad73dd85d9e429264a9f43f8cca51f852275 @josevalim josevalim committed Apr 27, 2012
Showing with 21 additions and 1 deletion.
  1. +5 −1 railties/lib/rails/queueing.rb
  2. +16 −0 railties/test/queueing/threaded_consumer_test.rb
View
6 railties/lib/rails/queueing.rb
@@ -42,7 +42,11 @@ def initialize(queue)
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
View
16 railties/test/queueing/threaded_consumer_test.rb
@@ -62,4 +62,20 @@ def teardown
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

0 comments on commit d8c3ad7

Please sign in to comment.