Skip to content

Commit

Permalink
Reraise the error so the outer executor can grab the error
Browse files Browse the repository at this point in the history
  • Loading branch information
npezza93 committed Oct 6, 2024
1 parent 0b05167 commit df712cf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/models/solid_queue/claimed_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def failed_with(error)
job.failed_with(error)
destroy!
end
raise error
end

private
Expand Down
18 changes: 10 additions & 8 deletions lib/solid_queue/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ def post(execution)
available_threads.decrement

future = Concurrent::Future.new(args: [ execution ], executor: executor) do |thread_execution|
thread_execution.perform
ensure
available_threads.increment
mutex.synchronize { on_idle.try(:call) if idle? }
end

future.add_observer do |_, _, error|
handle_thread_error(error) if error
begin
wrap_in_app_executor do
thread_execution.perform
end
rescue Exception
nil
ensure
available_threads.increment
mutex.synchronize { on_idle.try(:call) if idle? }
end
end

future.execute
Expand Down
22 changes: 22 additions & 0 deletions test/unit/worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ class WorkerTest < ActiveSupport::TestCase
subscriber = ErrorBuffer.new
Rails.error.subscribe(subscriber)

SolidQueue::ClaimedExecution::Result.expects(:new).raises(RuntimeError.new("everything is broken")).at_least_once

AddToBufferJob.perform_later "hey!"

@worker.start

wait_for_jobs_to_finish_for(1.second)
@worker.wake_up

assert_equal 1, subscriber.errors.count
assert_equal "everything is broken", subscriber.messages.first
ensure
Rails.error.unsubscribe(subscriber) if Rails.error.respond_to?(:unsubscribe)
SolidQueue.on_thread_error = original_on_thread_error
end

test "errors on claimed executions are reported via Rails error subscriber" do
original_on_thread_error, SolidQueue.on_thread_error = SolidQueue.on_thread_error, nil

subscriber = ErrorBuffer.new
Rails.error.subscribe(subscriber)

RaisingJob.perform_later(RuntimeError, "B")

@worker.start
Expand Down

0 comments on commit df712cf

Please sign in to comment.