mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Allow overriding exception handling in threaded consumer
This commit is contained in:
parent
1385388452
commit
8fbf2e197f
2 changed files with 24 additions and 1 deletions
|
@ -53,7 +53,7 @@ module Rails
|
|||
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 @@ module Rails
|
|||
@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
|
||||
|
|
|
@ -78,4 +78,23 @@ class TestThreadConsumer < ActiveSupport::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue