Skip to content

Commit 9dcf386

Browse files
authored
Merge pull request #8 from userlist/enable-retries-on-active-job-strategy
2 parents b873c4a + 56508f6 commit 9dcf386

4 files changed

Lines changed: 16 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Userlist for Ruby Changelog
22

3+
## Unreleased (main)
4+
5+
- Updates ActiveJob Worker to retry on Timeout::Error with polynomially longer wait times, up to 10 attempts
6+
37
## v0.9.0 (2024-03-19)
48

59
- Allows deleteing resources by using other identifiers (like email)

lib/userlist/push/strategies/active_job/worker.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class Push
55
module Strategies
66
class ActiveJob
77
class Worker < ::ActiveJob::Base
8+
retry_on Timeout::Error, wait: :polynomially_longer, attempts: 10
9+
810
def perform(method, *args)
911
client = Userlist::Push::Client.new
1012
client.public_send(method, *args)

spec/support/active_job.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'active_job'
2+
3+
ActiveJob::Base.queue_adapter = :test

spec/userlist/push/strategies/active_job/worker_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,11 @@
2828
described_class.perform_now('post', '/user', payload)
2929
described_class.perform_now('delete', '/user/identifier')
3030
end
31+
32+
it 'should retry the job on failure' do
33+
allow(client).to receive(:post).and_raise(Timeout::Error)
34+
35+
expect { described_class.perform_now('post', '/events', payload) }
36+
.to change(described_class.queue_adapter.enqueued_jobs, :size).by(1)
37+
end
3138
end

0 commit comments

Comments
 (0)