Skip to content

Commit

Permalink
Merge pull request #373 from npezza93/errors
Browse files Browse the repository at this point in the history
Report errors to the Rails error reporter
  • Loading branch information
rosa authored Nov 15, 2024
2 parents 0e59c07 + 29863c9 commit 42ce2ac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 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 @@ -64,6 +64,7 @@ def perform
finished
else
failed_with(result.error)
raise result.error
end
ensure
job.unblock_next_blocked_job
Expand Down
12 changes: 8 additions & 4 deletions test/models/solid_queue/claimed_execution_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class SolidQueue::ClaimedExecutionTest < ActiveSupport::TestCase
job = claimed_execution.job

assert_difference -> { SolidQueue::ClaimedExecution.count } => -1, -> { SolidQueue::FailedExecution.count } => 1 do
claimed_execution.perform
assert_raises RuntimeError do
claimed_execution.perform
end
end

assert_not job.reload.finished?
Expand All @@ -37,10 +39,12 @@ class SolidQueue::ClaimedExecutionTest < ActiveSupport::TestCase
test "job failures are reported via Rails error subscriber" do
subscriber = ErrorBuffer.new

with_error_subscriber(subscriber) do
claimed_execution = prepare_and_claim_job RaisingJob.perform_later(RuntimeError, "B")
assert_raises RuntimeError do
with_error_subscriber(subscriber) do
claimed_execution = prepare_and_claim_job RaisingJob.perform_later(RuntimeError, "B")

claimed_execution.perform
claimed_execution.perform
end
end

assert_equal 1, subscriber.errors.count
Expand Down
17 changes: 17 additions & 0 deletions test/unit/worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ class WorkerTest < ActiveSupport::TestCase
SolidQueue.on_thread_error = original_on_thread_error
end

test "errors on claimed executions are reported via Rails error subscriber" do
subscriber = ErrorBuffer.new
Rails.error.subscribe(subscriber)

RaisingJob.perform_later(RuntimeError, "B")

@worker.start

wait_for_jobs_to_finish_for(1.second)
@worker.wake_up

assert_equal 1, subscriber.errors.count
assert_equal "This is a RuntimeError exception", subscriber.messages.first
ensure
Rails.error.unsubscribe(subscriber) if Rails.error.respond_to?(:unsubscribe)
end

test "claim and process more enqueued jobs than the pool size allows to process at once" do
5.times do |i|
StoreResultJob.perform_later(:paused, pause: 0.1.second)
Expand Down

0 comments on commit 42ce2ac

Please sign in to comment.