diff --git a/app/jobs/api_entreprise/association_job.rb b/app/jobs/api_entreprise/association_job.rb index 2924cd142..fe2716c31 100644 --- a/app/jobs/api_entreprise/association_job.rb +++ b/app/jobs/api_entreprise/association_job.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::AssociationJob < ApplicationJob +class ApiEntreprise::AssociationJob < ApiEntreprise::Job def perform(etablissement_id, procedure_id) etablissement = Etablissement.find(etablissement_id) etablissement_params = ApiEntreprise::RNAAdapter.new(etablissement.siret, procedure_id).to_params diff --git a/app/jobs/api_entreprise/attestation_fiscale_job.rb b/app/jobs/api_entreprise/attestation_fiscale_job.rb index 328c8b1cf..aaa3c8cd3 100644 --- a/app/jobs/api_entreprise/attestation_fiscale_job.rb +++ b/app/jobs/api_entreprise/attestation_fiscale_job.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::AttestationFiscaleJob < ApplicationJob +class ApiEntreprise::AttestationFiscaleJob < ApiEntreprise::Job def perform(etablissement_id, procedure_id, user_id) etablissement = Etablissement.find(etablissement_id) etablissement_params = ApiEntreprise::AttestationFiscaleAdapter.new(etablissement.siret, procedure_id, user_id).to_params diff --git a/app/jobs/api_entreprise/attestation_sociale_job.rb b/app/jobs/api_entreprise/attestation_sociale_job.rb index bc499049e..581ed8037 100644 --- a/app/jobs/api_entreprise/attestation_sociale_job.rb +++ b/app/jobs/api_entreprise/attestation_sociale_job.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::AttestationSocialeJob < ApplicationJob +class ApiEntreprise::AttestationSocialeJob < ApiEntreprise::Job def perform(etablissement_id, procedure_id) etablissement = Etablissement.find(etablissement_id) etablissement_params = ApiEntreprise::AttestationSocialeAdapter.new(etablissement.siret, procedure_id).to_params diff --git a/app/jobs/api_entreprise/bilans_bdf_job.rb b/app/jobs/api_entreprise/bilans_bdf_job.rb index 34839a0f7..61c198ab7 100644 --- a/app/jobs/api_entreprise/bilans_bdf_job.rb +++ b/app/jobs/api_entreprise/bilans_bdf_job.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::BilansBdfJob < ApplicationJob +class ApiEntreprise::BilansBdfJob < ApiEntreprise::Job def perform(etablissement_id, procedure_id) etablissement = Etablissement.find(etablissement_id) etablissement_params = ApiEntreprise::BilansBdfAdapter.new(etablissement.siret, procedure_id).to_params diff --git a/app/jobs/api_entreprise/effectifs_annuels_job.rb b/app/jobs/api_entreprise/effectifs_annuels_job.rb index 2220d484a..d0c1c497e 100644 --- a/app/jobs/api_entreprise/effectifs_annuels_job.rb +++ b/app/jobs/api_entreprise/effectifs_annuels_job.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::EffectifsAnnuelsJob < ApplicationJob +class ApiEntreprise::EffectifsAnnuelsJob < ApiEntreprise::Job def perform(etablissement_id, procedure_id) etablissement = Etablissement.find(etablissement_id) etablissement_params = ApiEntreprise::EffectifsAnnuelsAdapter.new(etablissement.siret, procedure_id).to_params diff --git a/app/jobs/api_entreprise/effectifs_job.rb b/app/jobs/api_entreprise/effectifs_job.rb index faf1690e7..e668ef191 100644 --- a/app/jobs/api_entreprise/effectifs_job.rb +++ b/app/jobs/api_entreprise/effectifs_job.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::EffectifsJob < ApplicationJob +class ApiEntreprise::EffectifsJob < ApiEntreprise::Job def perform(etablissement_id, procedure_id) etablissement = Etablissement.find(etablissement_id) etablissement_params = ApiEntreprise::EffectifsAdapter.new(etablissement.siret, procedure_id, *get_current_valid_month_for_effectif).to_params diff --git a/app/jobs/api_entreprise/entreprise_job.rb b/app/jobs/api_entreprise/entreprise_job.rb index e22443a2d..02cf5caaf 100644 --- a/app/jobs/api_entreprise/entreprise_job.rb +++ b/app/jobs/api_entreprise/entreprise_job.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::EntrepriseJob < ApplicationJob +class ApiEntreprise::EntrepriseJob < ApiEntreprise::Job def perform(etablissement_id, procedure_id) etablissement = Etablissement.find(etablissement_id) etablissement_params = ApiEntreprise::EntrepriseAdapter.new(etablissement.siret, procedure_id).to_params diff --git a/app/jobs/api_entreprise/exercices_job.rb b/app/jobs/api_entreprise/exercices_job.rb index caf20a86b..fd8b5c682 100644 --- a/app/jobs/api_entreprise/exercices_job.rb +++ b/app/jobs/api_entreprise/exercices_job.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::ExercicesJob < ApplicationJob +class ApiEntreprise::ExercicesJob < ApiEntreprise::Job def perform(etablissement_id, procedure_id) etablissement = Etablissement.find(etablissement_id) etablissement_params = ApiEntreprise::ExercicesAdapter.new(etablissement.siret, procedure_id).to_params diff --git a/app/jobs/api_entreprise/job.rb b/app/jobs/api_entreprise/job.rb new file mode 100644 index 000000000..45d21b1ad --- /dev/null +++ b/app/jobs/api_entreprise/job.rb @@ -0,0 +1,6 @@ +class ApiEntreprise::Job < ApplicationJob + DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS = 5 + def max_attempts + ENV[MAX_ATTEMPTS_API_ENTREPRISE_JOBS].to_i || DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS + end +end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index 7538ed4f5..d7de32266 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,4 +1,6 @@ class ApplicationJob < ActiveJob::Base + DEFAULT_MAX_ATTEMPTS_JOBS = 25 + before_perform do |job| Rails.logger.info("#{job.class.name} started at #{Time.zone.now}") end @@ -18,4 +20,8 @@ class ApplicationJob < ActiveJob::Base def error(job, exception) Raven.capture_exception(exception) end + + def max_attempts + ENV["MAX_ATTEMPTS_JOBS"].to_i || DEFAULT_MAX_ATTEMPTS_JOBS + end end diff --git a/config/env.example b/config/env.example index 7b3515bd5..64d3a8f6a 100644 --- a/config/env.example +++ b/config/env.example @@ -108,3 +108,7 @@ UNIVERSIGN_USERPWD="" # API Geo / Adresse API_ADRESSE_URL="https://api-adresse.data.gouv.fr" API_GEO_URL="https://geo.api.gouv.fr" + +# Modifier le nb de tentatives de relance de job si echec +# MAX_ATTEMPTS_JOBS=25 +# MAX_ATTEMPTS_API_ENTREPRISE_JOBS=5