After maximum ammount of retries discard the job and log exception
This commit is contained in:
parent
a591d5528e
commit
9156754cf6
9 changed files with 38 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
||||||
class ApiEntreprise::AssociationJob < ApiEntreprise::Job
|
class ApiEntreprise::AssociationJob < ApiEntreprise::Job
|
||||||
def perform(etablissement_id, procedure_id)
|
def perform(etablissement_id, procedure_id)
|
||||||
etablissement = Etablissement.find(etablissement_id)
|
find_etablissement(etablissement_id)
|
||||||
etablissement_params = ApiEntreprise::RNAAdapter.new(etablissement.siret, procedure_id).to_params
|
etablissement_params = ApiEntreprise::RNAAdapter.new(etablissement.siret, procedure_id).to_params
|
||||||
etablissement.update!(etablissement_params)
|
etablissement.update!(etablissement_params)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class ApiEntreprise::AttestationFiscaleJob < ApiEntreprise::Job
|
class ApiEntreprise::AttestationFiscaleJob < ApiEntreprise::Job
|
||||||
def perform(etablissement_id, procedure_id, user_id)
|
def perform(etablissement_id, procedure_id, user_id)
|
||||||
etablissement = Etablissement.find(etablissement_id)
|
find_etablissement(etablissement_id)
|
||||||
etablissement_params = ApiEntreprise::AttestationFiscaleAdapter.new(etablissement.siret, procedure_id, user_id).to_params
|
etablissement_params = ApiEntreprise::AttestationFiscaleAdapter.new(etablissement.siret, procedure_id, user_id).to_params
|
||||||
attestation_fiscale_url = etablissement_params.delete(:entreprise_attestation_fiscale_url)
|
attestation_fiscale_url = etablissement_params.delete(:entreprise_attestation_fiscale_url)
|
||||||
etablissement.upload_attestation_fiscale(attestation_fiscale_url) if attestation_fiscale_url.present?
|
etablissement.upload_attestation_fiscale(attestation_fiscale_url) if attestation_fiscale_url.present?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class ApiEntreprise::AttestationSocialeJob < ApiEntreprise::Job
|
class ApiEntreprise::AttestationSocialeJob < ApiEntreprise::Job
|
||||||
def perform(etablissement_id, procedure_id)
|
def perform(etablissement_id, procedure_id)
|
||||||
etablissement = Etablissement.find(etablissement_id)
|
find_etablissement(etablissement_id)
|
||||||
etablissement_params = ApiEntreprise::AttestationSocialeAdapter.new(etablissement.siret, procedure_id).to_params
|
etablissement_params = ApiEntreprise::AttestationSocialeAdapter.new(etablissement.siret, procedure_id).to_params
|
||||||
attestation_sociale_url = etablissement_params.delete(:entreprise_attestation_sociale_url)
|
attestation_sociale_url = etablissement_params.delete(:entreprise_attestation_sociale_url)
|
||||||
etablissement.upload_attestation_sociale(attestation_sociale_url) if attestation_sociale_url.present?
|
etablissement.upload_attestation_sociale(attestation_sociale_url) if attestation_sociale_url.present?
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class ApiEntreprise::BilansBdfJob < ApiEntreprise::Job
|
class ApiEntreprise::BilansBdfJob < ApiEntreprise::Job
|
||||||
def perform(etablissement_id, procedure_id)
|
def perform(etablissement_id, procedure_id)
|
||||||
etablissement = Etablissement.find(etablissement_id)
|
find_etablissement(etablissement_id)
|
||||||
etablissement_params = ApiEntreprise::BilansBdfAdapter.new(etablissement.siret, procedure_id).to_params
|
etablissement_params = ApiEntreprise::BilansBdfAdapter.new(etablissement.siret, procedure_id).to_params
|
||||||
etablissement.update!(etablissement_params)
|
etablissement.update!(etablissement_params)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class ApiEntreprise::EffectifsAnnuelsJob < ApiEntreprise::Job
|
class ApiEntreprise::EffectifsAnnuelsJob < ApiEntreprise::Job
|
||||||
def perform(etablissement_id, procedure_id)
|
def perform(etablissement_id, procedure_id)
|
||||||
etablissement = Etablissement.find(etablissement_id)
|
find_etablissement(etablissement_id)
|
||||||
etablissement_params = ApiEntreprise::EffectifsAnnuelsAdapter.new(etablissement.siret, procedure_id).to_params
|
etablissement_params = ApiEntreprise::EffectifsAnnuelsAdapter.new(etablissement.siret, procedure_id).to_params
|
||||||
etablissement.update!(etablissement_params)
|
etablissement.update!(etablissement_params)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class ApiEntreprise::EffectifsJob < ApiEntreprise::Job
|
class ApiEntreprise::EffectifsJob < ApiEntreprise::Job
|
||||||
def perform(etablissement_id, procedure_id)
|
def perform(etablissement_id, procedure_id)
|
||||||
etablissement = Etablissement.find(etablissement_id)
|
find_etablissement(etablissement_id)
|
||||||
# may 2020 is at the moment the most actual info for effectifs endpoint
|
# may 2020 is at the moment the most actual info for effectifs endpoint
|
||||||
etablissement_params = ApiEntreprise::EffectifsAdapter.new(etablissement.siret, procedure_id, "2020", "05").to_params
|
etablissement_params = ApiEntreprise::EffectifsAdapter.new(etablissement.siret, procedure_id, "2020", "05").to_params
|
||||||
etablissement.update!(etablissement_params)
|
etablissement.update!(etablissement_params)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class ApiEntreprise::EntrepriseJob < ApiEntreprise::Job
|
class ApiEntreprise::EntrepriseJob < ApiEntreprise::Job
|
||||||
def perform(etablissement_id, procedure_id)
|
def perform(etablissement_id, procedure_id)
|
||||||
etablissement = Etablissement.find(etablissement_id)
|
find_etablissement(etablissement_id)
|
||||||
etablissement_params = ApiEntreprise::EntrepriseAdapter.new(etablissement.siret, procedure_id).to_params
|
etablissement_params = ApiEntreprise::EntrepriseAdapter.new(etablissement.siret, procedure_id).to_params
|
||||||
etablissement.update!(etablissement_params)
|
etablissement.update!(etablissement_params)
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ class ApiEntreprise::ExercicesJob < ApiEntreprise::Job
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform(etablissement_id, procedure_id)
|
def perform(etablissement_id, procedure_id)
|
||||||
etablissement = Etablissement.find(etablissement_id)
|
find_etablissement(etablissement_id)
|
||||||
etablissement_params = ApiEntreprise::ExercicesAdapter.new(etablissement.siret, procedure_id).to_params
|
etablissement_params = ApiEntreprise::ExercicesAdapter.new(etablissement.siret, procedure_id).to_params
|
||||||
etablissement.update!(etablissement_params)
|
etablissement.update!(etablissement_params)
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,9 +8,12 @@ class ApiEntreprise::Job < ApplicationJob
|
||||||
# - bdf: erreur interne
|
# - bdf: erreur interne
|
||||||
# so we retry every day for 5 days
|
# so we retry every day for 5 days
|
||||||
# same logic for ServiceUnavailable
|
# same logic for ServiceUnavailable
|
||||||
retry_on ApiEntreprise::API::Error::ServiceUnavailable,
|
rescue_from(ApiEntreprise::API::Error::ServiceUnavailable) do |exception|
|
||||||
ApiEntreprise::API::Error::BadGateway,
|
retry_or_discard(exception)
|
||||||
wait: 1.day
|
end
|
||||||
|
rescue_from(ApiEntreprise::API::Error::BadGateway) do |exception|
|
||||||
|
retry_or_discard(exception)
|
||||||
|
end
|
||||||
|
|
||||||
# We guess the backend is slow but not broken
|
# We guess the backend is slow but not broken
|
||||||
# and the information we are looking for is available
|
# and the information we are looking for is available
|
||||||
|
@ -33,7 +36,31 @@ class ApiEntreprise::Job < ApplicationJob
|
||||||
# override ApplicationJob#error to avoid reporting to sentry
|
# override ApplicationJob#error to avoid reporting to sentry
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def log_job_exception(exception)
|
||||||
|
if etablissement.present?
|
||||||
|
if etablissement.dossier.present?
|
||||||
|
etablissement.dossier.log_api_entreprise_job_exception(exception)
|
||||||
|
elsif etablissement.champ.present?
|
||||||
|
etablissement.champ.log_fetch_external_data_exception(exception)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def retry_or_discard(exception)
|
||||||
|
if executions < max_attempts
|
||||||
|
retry_job wait: 1.day
|
||||||
|
else
|
||||||
|
log_job_exception(exception)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def max_attempts
|
def max_attempts
|
||||||
ENV.fetch("MAX_ATTEMPTS_API_ENTREPRISE_JOBS", DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS).to_i
|
ENV.fetch("MAX_ATTEMPTS_API_ENTREPRISE_JOBS", DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS).to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attr_reader :etablissement
|
||||||
|
|
||||||
|
def find_etablissement(etablissement_id)
|
||||||
|
@etablissement = Etablissement.find(etablissement_id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue