Skip to content
Browse files

Allow overriding exception handling in threaded consumer

  • Loading branch information...
1 parent 1385388 commit 8fbf2e197f0a327ab95bc85b3d3d683e68e09cf3 @carlosantoniodasilva carlosantoniodasilva committed
Showing with 24 additions and 1 deletion.
  1. +5 −1 railties/lib/rails/queueing.rb
  2. +19 −0 railties/test/queueing/threaded_consumer_test.rb
View
6 railties/lib/rails/queueing.rb
@@ -53,7 +53,7 @@ def start
begin
job.run
rescue Exception => e
- Rails.logger.error "Job Error: #{e.message}\n#{e.backtrace.join("\n")}"
+ handle_exception e
end
end
end
@@ -64,6 +64,10 @@ def shutdown
@queue.push nil
@thread.join
end
+
+ def handle_exception(e)
+ Rails.logger.error "Job Error: #{e.message}\n#{e.backtrace.join("\n")}"
+ end
end
end
end
View
19 railties/test/queueing/threaded_consumer_test.rb
@@ -78,4 +78,23 @@ def teardown
assert_equal 1, logger.logged(:error).size
assert_match(/Job Error: RuntimeError: Error!/, logger.logged(:error).last)
end
+
+ test "test overriding exception handling" do
+ @consumer.shutdown
+ @consumer = Class.new(Rails::Queueing::ThreadedConsumer) do
+ attr_reader :last_error
+ def handle_exception(e)
+ @last_error = e.message
+ end
+ end.start(@queue)
+
+ job = Job.new(1) do
+ raise "RuntimeError: Error!"
+ end
+
+ @queue.push job
+ sleep 0.1
+
+ assert_equal "RuntimeError: Error!", @consumer.last_error
+ end
end

0 comments on commit 8fbf2e1

Please sign in to comment.
Something went wrong with that request. Please try again.