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

Configure ActiveJob retry (max 5 attempts) #7

Merged
merged 1 commit into from
Jun 7, 2022
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 lib/dfe/analytics/send_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module DfE
module Analytics
class SendEvents < ActiveJob::Base
queue_as { DfE::Analytics.config.queue }
retry_on StandardError, wait: :exponentially_longer, attempts: 5

def self.do(events)
if DfE::Analytics.async?
Expand Down
18 changes: 18 additions & 0 deletions spec/dfe/analytics/send_events_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

RSpec.describe DfE::Analytics::SendEvents do
include ActiveJob::TestHelper

describe '#perform' do
let(:event) do
{
Expand Down Expand Up @@ -42,5 +44,21 @@
end
end
end

describe 'retry behaviour' do
before do
# we don't want to define a permanent exception, just one for this test
stub_const('DummyException', Class.new(StandardError))
end

it 'makes 5 attempts' do
allow(DfE::Analytics).to receive(:log_only?).and_raise(DummyException)

assert_performed_jobs 5 do
described_class.perform_later([])
rescue DummyException # the final exception won’t be caught
end
end
end
end
end