Skip to content

Commit 1fe831c

Browse files
committed
Toggle whether errors should be reraised
1 parent 4fb5b9c commit 1fe831c

File tree

7 files changed

+18
-19
lines changed

7 files changed

+18
-19
lines changed

app/models/solid_queue/claimed_execution.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def release_all
3636
end
3737
end
3838

39-
def fail_all_with(error)
39+
def fail_all_with(error, reraise:)
4040
SolidQueue.instrument(:fail_many_claimed) do |payload|
4141
includes(:job).tap do |executions|
42-
executions.each { |execution| execution.failed_with(error) }
42+
executions.each { |execution| execution.failed_with(error, reraise: reraise) }
4343

4444
payload[:process_ids] = executions.map(&:process_id).uniq
4545
payload[:job_ids] = executions.map(&:job_id).uniq
@@ -63,7 +63,7 @@ def perform
6363
if result.success?
6464
finished
6565
else
66-
failed_with(result.error)
66+
failed_with(result.error, reraise: true)
6767
end
6868
ensure
6969
job.unblock_next_blocked_job
@@ -82,12 +82,12 @@ def discard
8282
raise UndiscardableError, "Can't discard a job in progress"
8383
end
8484

85-
def failed_with(error)
85+
def failed_with(error, reraise:)
8686
transaction do
8787
job.failed_with(error)
8888
destroy!
8989
end
90-
raise error
90+
raise error if reraise
9191
end
9292

9393
private

app/models/solid_queue/process/executor.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ module Executor
1111
after_destroy :release_all_claimed_executions
1212
end
1313

14-
def fail_all_claimed_executions_with(error)
14+
def fail_all_claimed_executions_with(error, reraise:)
1515
if claims_executions?
16-
claimed_executions.fail_all_with(error)
16+
claimed_executions.fail_all_with(error, reraise: reraise)
1717
end
1818
end
1919

app/models/solid_queue/process/prunable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def prune(excluding: nil)
2323

2424
def prune
2525
error = Processes::ProcessPrunedError.new(last_heartbeat_at)
26-
fail_all_claimed_executions_with(error)
26+
fail_all_claimed_executions_with(error, reraise: false)
2727

2828
deregister(pruned: true)
2929
end

lib/solid_queue/pool.rb

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

2121
future = Concurrent::Future.new(args: [ execution ], executor: executor) do |thread_execution|
22-
begin
23-
wrap_in_app_executor do
24-
thread_execution.perform
25-
end
26-
rescue Exception
27-
nil
22+
wrap_in_app_executor do
23+
thread_execution.perform
2824
ensure
2925
available_threads.increment
3026
mutex.synchronize { on_idle.try(:call) if idle? }
3127
end
3228
end
3329

30+
future.add_observer do |_, _, error|
31+
handle_thread_error(error) if error
32+
end
33+
3434
future.execute
3535
end
3636

lib/solid_queue/supervisor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def replace_fork(pid, status)
173173
def handle_claimed_jobs_by(terminated_fork, status)
174174
if registered_process = process.supervisees.find_by(name: terminated_fork.name)
175175
error = Processes::ProcessExitError.new(status)
176-
registered_process.fail_all_claimed_executions_with(error)
176+
registered_process.fail_all_claimed_executions_with(error, reraise: false)
177177
end
178178
end
179179

lib/solid_queue/supervisor/maintenance.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def prune_dead_processes
2929

3030
def fail_orphaned_executions
3131
wrap_in_app_executor do
32-
ClaimedExecution.orphaned.fail_all_with(Processes::ProcessMissingError.new)
32+
ClaimedExecution.orphaned.
33+
fail_all_with(Processes::ProcessMissingError.new, reraise: false)
3334
end
3435
end
3536
end

test/models/solid_queue/claimed_execution_test.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ class SolidQueue::ClaimedExecutionTest < ActiveSupport::TestCase
6666
claimed_execution = prepare_and_claim_job AddToBufferJob.perform_later(42)
6767
job = claimed_execution.job
6868
assert_difference -> { SolidQueue::ClaimedExecution.count } => -1, -> { SolidQueue::FailedExecution.count } => 1 do
69-
assert_raises RuntimeError do
70-
claimed_execution.failed_with(RuntimeError.new)
71-
end
69+
claimed_execution.failed_with(RuntimeError.new, reraise: false)
7270
end
7371

7472
assert job.reload.failed?

0 commit comments

Comments
 (0)