Merge pull request #5640 from Keirua/ignore-missing-etablissement
do not run ApiEntreprise jobs on missing etablissements
This commit is contained in:
commit
d469d4ddd1
2 changed files with 14 additions and 0 deletions
|
@ -3,6 +3,10 @@ class ApiEntreprise::Job < ApplicationJob
|
||||||
|
|
||||||
DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS = 5
|
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|
|
rescue_from(ApiEntreprise::API::ResourceNotFound) do |exception|
|
||||||
error(self, exception)
|
error(self, exception)
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,4 +18,14 @@ RSpec.describe ApiEntreprise::AssociationJob, type: :job do
|
||||||
subject
|
subject
|
||||||
expect(Etablissement.find(etablissement.id).association_rna).to eq('W595001988')
|
expect(Etablissement.find(etablissement.id).association_rna).to eq('W595001988')
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue