fix(data): backfill etablissement as degraded mode

This commit is contained in:
Martin 2022-09-22 18:02:47 +02:00
parent 9b929c86ea
commit daeab50321
2 changed files with 30 additions and 0 deletions

View file

@ -34,6 +34,15 @@ class APIEntrepriseService
etablissement etablissement
end end
def update_etablissement_from_degraded_mode(etablissement)
procedure_id = etablissement.dossier.procedure.id
siret = etablissement.siret
etablissement_params = APIEntreprise::EtablissementAdapter.new(siret, procedure_id).to_params
return nil if etablissement_params.empty?
etablissement.update!(etablissement_params)
end
def perform_later_fetch_jobs(etablissement, procedure_id, user_id, wait: nil) def perform_later_fetch_jobs(etablissement, procedure_id, user_id, wait: nil)
[ [
APIEntreprise::EntrepriseJob, APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob, APIEntreprise::EntrepriseJob, APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob,

View file

@ -0,0 +1,21 @@
namespace :after_party do
desc 'Deployment task: backfill_etablissement_as_degraded_mode'
task backfill_etablissement_as_degraded_mode: :environment do
puts "Running deploy task 'backfill_etablissement_as_degraded_mode'"
Etablissement.joins(:dossier).where(adresse: nil).find_each do |etablissement|
begin
APIEntrepriseService.update_etablissement_from_degraded_mode(etablissement)
rescue => e
Sentry.capture_exception(e)
end
sleep((0.5).second)
end
# Put your task implementation HERE.
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end