Skip to content

Commit

Permalink
simplify raising
Browse files Browse the repository at this point in the history
  • Loading branch information
npezza93 committed Nov 13, 2024
1 parent 4c9a81b commit 29863c9
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
10 changes: 5 additions & 5 deletions app/models/solid_queue/claimed_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def release_all
end
end

def fail_all_with(error, reraise:)
def fail_all_with(error)
SolidQueue.instrument(:fail_many_claimed) do |payload|
includes(:job).tap do |executions|
executions.each { |execution| execution.failed_with(error, reraise: reraise) }
executions.each { |execution| execution.failed_with(error) }

payload[:process_ids] = executions.map(&:process_id).uniq
payload[:job_ids] = executions.map(&:job_id).uniq
Expand All @@ -63,7 +63,8 @@ def perform
if result.success?
finished
else
failed_with(result.error, reraise: true)
failed_with(result.error)
raise result.error
end
ensure
job.unblock_next_blocked_job
Expand All @@ -82,12 +83,11 @@ def discard
raise UndiscardableError, "Can't discard a job in progress"
end

def failed_with(error, reraise:)
def failed_with(error)
transaction do
job.failed_with(error)
destroy!
end
raise error if reraise
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/models/solid_queue/process/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ module Executor
after_destroy :release_all_claimed_executions
end

def fail_all_claimed_executions_with(error, reraise:)
def fail_all_claimed_executions_with(error)
if claims_executions?
claimed_executions.fail_all_with(error, reraise: reraise)
claimed_executions.fail_all_with(error)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/solid_queue/process/prunable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def prune(excluding: nil)

def prune
error = Processes::ProcessPrunedError.new(last_heartbeat_at)
fail_all_claimed_executions_with(error, reraise: false)
fail_all_claimed_executions_with(error)

deregister(pruned: true)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/solid_queue/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def replace_fork(pid, status)
def handle_claimed_jobs_by(terminated_fork, status)
if registered_process = process.supervisees.find_by(name: terminated_fork.name)
error = Processes::ProcessExitError.new(status)
registered_process.fail_all_claimed_executions_with(error, reraise: false)
registered_process.fail_all_claimed_executions_with(error)
end
end

Expand Down
3 changes: 1 addition & 2 deletions lib/solid_queue/supervisor/maintenance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def prune_dead_processes

def fail_orphaned_executions
wrap_in_app_executor do
ClaimedExecution.orphaned.
fail_all_with(Processes::ProcessMissingError.new, reraise: false)
ClaimedExecution.orphaned.fail_all_with(Processes::ProcessMissingError.new)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/models/solid_queue/claimed_execution_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SolidQueue::ClaimedExecutionTest < ActiveSupport::TestCase
job = claimed_execution.job

assert_difference -> { SolidQueue::ClaimedExecution.count } => -1, -> { SolidQueue::FailedExecution.count } => 1 do
claimed_execution.failed_with(RuntimeError.new, reraise: false)
claimed_execution.failed_with(RuntimeError.new)
end

assert job.reload.failed?
Expand Down

0 comments on commit 29863c9

Please sign in to comment.