Add job exception log methods to champ and dossier
This commit is contained in:
parent
78a07ef021
commit
a591d5528e
5 changed files with 45 additions and 2 deletions
|
@ -137,6 +137,12 @@ class Champ < ApplicationRecord
|
|||
type_de_champ.stable_id
|
||||
end
|
||||
|
||||
def log_fetch_external_data_exception(exception)
|
||||
exceptions = self.fetch_external_data_exceptions ||= []
|
||||
exceptions << exception.inspect
|
||||
update_column(:fetch_external_data_exceptions, exceptions)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def needs_dossier_id?
|
||||
|
|
|
@ -820,6 +820,12 @@ class Dossier < ApplicationRecord
|
|||
}
|
||||
end
|
||||
|
||||
def log_api_entreprise_job_exception(exception)
|
||||
exceptions = self.api_entreprise_job_exceptions ||= []
|
||||
exceptions << exception.inspect
|
||||
update_column(:api_entreprise_job_exceptions, exceptions)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def geo_areas
|
||||
|
|
|
@ -4,6 +4,8 @@ RSpec.describe ApiEntreprise::Job, type: :job do
|
|||
# https://api.rubyonrails.org/classes/ActiveJob/Exceptions/ClassMethods.html
|
||||
# #method-i-retry_on
|
||||
describe '#perform' do
|
||||
let(:dossier) { create(:dossier, :with_entreprise) }
|
||||
|
||||
context 'when a un retryable error is raised' do
|
||||
let(:errors) { [:standard_error] }
|
||||
|
||||
|
@ -17,20 +19,25 @@ RSpec.describe ApiEntreprise::Job, type: :job do
|
|||
|
||||
it 'retries 5 times' do
|
||||
ensure_errors_force_n_retry(errors, 5)
|
||||
expect(dossier.reload.api_entreprise_job_exceptions.first).to match('ApiEntreprise::API::Error::ServiceUnavailable')
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_errors_force_n_retry(errors, retry_nb)
|
||||
etablissement = dossier.etablissement
|
||||
|
||||
errors.each do |error|
|
||||
assert_performed_jobs(retry_nb) do
|
||||
ErrorJob.perform_later(error) rescue StandardError
|
||||
ErrorJob.perform_later(error, etablissement) rescue StandardError
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ErrorJob < ApiEntreprise::Job
|
||||
def perform(error)
|
||||
def perform(error, etablissement)
|
||||
@etablissement = etablissement
|
||||
|
||||
response = OpenStruct.new(
|
||||
effective_url: 'http://host.com/path',
|
||||
code: '666',
|
||||
|
|
|
@ -510,4 +510,16 @@ describe Champ do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#log_fetch_external_data_exception' do
|
||||
let(:champ) { create(:champ_siret) }
|
||||
|
||||
context "add execption to the log" do
|
||||
before do
|
||||
champ.log_fetch_external_data_exception(StandardError.new('My special exception!'))
|
||||
end
|
||||
|
||||
it { expect(champ.fetch_external_data_exceptions).to eq(['#<StandardError: My special exception!>']) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1424,4 +1424,16 @@ describe Dossier do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#log_api_entreprise_job_exception' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
|
||||
context "add execption to the log" do
|
||||
before do
|
||||
dossier.log_api_entreprise_job_exception(StandardError.new('My special exception!'))
|
||||
end
|
||||
|
||||
it { expect(dossier.api_entreprise_job_exceptions).to eq(['#<StandardError: My special exception!>']) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue