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

Enable retries on active job strategy #8

Merged
merged 5 commits into from
Oct 21, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Userlist for Ruby Changelog

## Unreleased (main)

- Updates ActiveJob Worker to retry on Timeout::Error with polynomially longer wait times, up to 10 attempts

## v0.9.0 (2024-03-19)

- Allows deleteing resources by using other identifiers (like email)
Expand Down
2 changes: 2 additions & 0 deletions lib/userlist/push/strategies/active_job/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class Push
module Strategies
class ActiveJob
class Worker < ::ActiveJob::Base
retry_on Timeout::Error, wait: :polynomially_longer, attempts: 10

def perform(method, *args)
client = Userlist::Push::Client.new
client.public_send(method, *args)
Expand Down
3 changes: 3 additions & 0 deletions spec/support/active_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'active_job'

ActiveJob::Base.queue_adapter = :test
7 changes: 7 additions & 0 deletions spec/userlist/push/strategies/active_job/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
described_class.perform_now('post', '/user', payload)
described_class.perform_now('delete', '/user/identifier')
end

it 'should retry the job on failure' do
allow(client).to receive(:post).and_raise(Timeout::Error)

expect { described_class.perform_now('post', '/events', payload) }
.to change(described_class.queue_adapter.enqueued_jobs, :size).by(1)
end
end