Skip to content

Commit df712cf

Browse files
committed
Reraise the error so the outer executor can grab the error
1 parent 0b05167 commit df712cf

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

app/models/solid_queue/claimed_execution.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def failed_with(error)
8787
job.failed_with(error)
8888
destroy!
8989
end
90+
raise error
9091
end
9192

9293
private

lib/solid_queue/pool.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ def post(execution)
1919
available_threads.decrement
2020

2121
future = Concurrent::Future.new(args: [ execution ], executor: executor) do |thread_execution|
22-
thread_execution.perform
23-
ensure
24-
available_threads.increment
25-
mutex.synchronize { on_idle.try(:call) if idle? }
26-
end
27-
28-
future.add_observer do |_, _, error|
29-
handle_thread_error(error) if error
22+
begin
23+
wrap_in_app_executor do
24+
thread_execution.perform
25+
end
26+
rescue Exception
27+
nil
28+
ensure
29+
available_threads.increment
30+
mutex.synchronize { on_idle.try(:call) if idle? }
31+
end
3032
end
3133

3234
future.execute

test/unit/worker_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@ class WorkerTest < ActiveSupport::TestCase
5151
subscriber = ErrorBuffer.new
5252
Rails.error.subscribe(subscriber)
5353

54+
SolidQueue::ClaimedExecution::Result.expects(:new).raises(RuntimeError.new("everything is broken")).at_least_once
55+
56+
AddToBufferJob.perform_later "hey!"
57+
58+
@worker.start
59+
60+
wait_for_jobs_to_finish_for(1.second)
61+
@worker.wake_up
62+
63+
assert_equal 1, subscriber.errors.count
64+
assert_equal "everything is broken", subscriber.messages.first
65+
ensure
66+
Rails.error.unsubscribe(subscriber) if Rails.error.respond_to?(:unsubscribe)
67+
SolidQueue.on_thread_error = original_on_thread_error
68+
end
69+
70+
test "errors on claimed executions are reported via Rails error subscriber" do
71+
original_on_thread_error, SolidQueue.on_thread_error = SolidQueue.on_thread_error, nil
72+
73+
subscriber = ErrorBuffer.new
74+
Rails.error.subscribe(subscriber)
75+
5476
RaisingJob.perform_later(RuntimeError, "B")
5577

5678
@worker.start

0 commit comments

Comments
 (0)