Merge pull request #5640 from Keirua/ignore-missing-etablissement

do not run ApiEntreprise jobs on missing etablissements
This commit is contained in:
Keirua 2020-09-28 17:58:43 +02:00 committed by GitHub
commit d469d4ddd1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View file

@ -3,6 +3,10 @@ class ApiEntreprise::Job < ApplicationJob
DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS = 5
# If by the time the job runs the Etablissement has been deleted
# (it can happen through EtablissementUpdateJob for instance), ignore the job
discard_on ActiveRecord::RecordNotFound
rescue_from(ApiEntreprise::API::ResourceNotFound) do |exception|
error(self, exception)
end

View file

@ -18,4 +18,14 @@ RSpec.describe ApiEntreprise::AssociationJob, type: :job do
subject
expect(Etablissement.find(etablissement.id).association_rna).to eq('W595001988')
end
context "when the etablissement has been deleted" do
before do
allow_any_instance_of(Etablissement).to receive(:find) { raise ActiveRecord::RecordNotFound }
end
it "ignores the error" do
expect { subject }.not_to raise_error
end
end
end