retry each day during 5 days to fetch attestation social

This commit is contained in:
simon lehericey 2020-10-27 21:13:06 +01:00 committed by LeSim (Rebase PR Action)
parent 52c2ea1905
commit c563956a9f
4 changed files with 27 additions and 2 deletions

View file

@ -1,3 +1,5 @@
include ActiveJob::TestHelper
RSpec.describe ApiEntreprise::AttestationSocialeJob, type: :job do
let(:etablissement) { create(:etablissement, siret: siret) }
let(:siret) { '41816609600069' }
@ -21,4 +23,20 @@ RSpec.describe ApiEntreprise::AttestationSocialeJob, type: :job do
subject
expect(Etablissement.find(etablissement.id).entreprise_attestation_sociale).to be_attached
end
context 'when ApiEntreprise::API::ServiceUnavailable is raised' do
# https://api.rubyonrails.org/classes/ActiveJob/Exceptions/ClassMethods.html#method-i-retry_on
# retry on will try 5 times and then bubble up the error
it 'makes 5 attempts' do
assert_performed_jobs 5 do
ServiceUnavailableJob.perform_later rescue ApiEntreprise::API::ServiceUnavailable
end
end
end
class ServiceUnavailableJob < ApiEntreprise::AttestationSocialeJob
def perform
raise ApiEntreprise::API::ServiceUnavailable
end
end
end