Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report errors to the Rails error reporter #373

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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