Skip to content

Commit 42ce2ac

Browse files
authored
Merge pull request #373 from npezza93/errors
Report errors to the Rails error reporter
2 parents 0e59c07 + 29863c9 commit 42ce2ac

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

app/models/solid_queue/claimed_execution.rb

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def perform
6464
finished
6565
else
6666
failed_with(result.error)
67+
raise result.error
6768
end
6869
ensure
6970
job.unblock_next_blocked_job

test/models/solid_queue/claimed_execution_test.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ class SolidQueue::ClaimedExecutionTest < ActiveSupport::TestCase
2222
job = claimed_execution.job
2323

2424
assert_difference -> { SolidQueue::ClaimedExecution.count } => -1, -> { SolidQueue::FailedExecution.count } => 1 do
25-
claimed_execution.perform
25+
assert_raises RuntimeError do
26+
claimed_execution.perform
27+
end
2628
end
2729

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

40-
with_error_subscriber(subscriber) do
41-
claimed_execution = prepare_and_claim_job RaisingJob.perform_later(RuntimeError, "B")
42+
assert_raises RuntimeError do
43+
with_error_subscriber(subscriber) do
44+
claimed_execution = prepare_and_claim_job RaisingJob.perform_later(RuntimeError, "B")
4245

43-
claimed_execution.perform
46+
claimed_execution.perform
47+
end
4448
end
4549

4650
assert_equal 1, subscriber.errors.count

test/unit/worker_test.rb

+17
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ class WorkerTest < ActiveSupport::TestCase
6767
SolidQueue.on_thread_error = original_on_thread_error
6868
end
6969

70+
test "errors on claimed executions are reported via Rails error subscriber" do
71+
subscriber = ErrorBuffer.new
72+
Rails.error.subscribe(subscriber)
73+
74+
RaisingJob.perform_later(RuntimeError, "B")
75+
76+
@worker.start
77+
78+
wait_for_jobs_to_finish_for(1.second)
79+
@worker.wake_up
80+
81+
assert_equal 1, subscriber.errors.count
82+
assert_equal "This is a RuntimeError exception", subscriber.messages.first
83+
ensure
84+
Rails.error.unsubscribe(subscriber) if Rails.error.respond_to?(:unsubscribe)
85+
end
86+
7087
test "claim and process more enqueued jobs than the pool size allows to process at once" do
7188
5.times do |i|
7289
StoreResultJob.perform_later(:paused, pause: 0.1.second)

0 commit comments

Comments
 (0)