Skip to content

Commit 0ab4344

Browse files
committed
Change retry strategy to :polynomially_longer
1 parent 1233391 commit 0ab4344

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

app/jobs/update_job.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class UpdateJob < ApplicationJob
77
include JobWithTimestamp
88
queue_as :default
99

10-
retry_on Errno::ECONNREFUSED, wait: :exponentially_longer, attempts: 10
11-
retry_on Model::LockTimeoutError, wait: :exponentially_longer, attempts: 10
10+
retry_on Errno::ECONNREFUSED, wait: :polynomially_longer, attempts: 10
11+
retry_on Model::LockTimeoutError, wait: :polynomially_longer, attempts: 10
1212

1313
self.deduplicate = true
1414

test/jobs/update_job_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,27 @@ class UpdateJobTest < ActiveJob::TestCase
5353
end
5454
end
5555
end
56+
57+
test 'retries on Errno::ECONNREFUSED' do
58+
model = Model.create!(tenant: tenants(:two), record: applications(:two))
59+
call_count = 0
60+
61+
# Stub FetchService.call to raise Errno::ECONNREFUSED on first call, succeed on second
62+
FetchService.stub :call, lambda { |_|
63+
call_count += 1
64+
if call_count == 1
65+
raise Errno::ECONNREFUSED, 'Connection refused'
66+
else
67+
Entry.new
68+
end
69+
} do
70+
71+
perform_enqueued_jobs do
72+
UpdateJob.perform_later(model)
73+
end
74+
75+
# Verify that the job was called twice (initial attempt + 1 retry)
76+
assert_equal 2, call_count, 'UpdateJob should retry once after Errno::ECONNREFUSED'
77+
end
78+
end
5679
end

0 commit comments

Comments
 (0)