2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-10-14 15:58:32 +02:00
|
|
|
# TODO: remove this job in a few days once all failed etablissements are queued as separate jobs
|
2022-09-23 15:12:25 +02:00
|
|
|
class Cron::BackfillSiretDegradedModeJob < Cron::CronJob
|
|
|
|
self.schedule_expression = "every 2 hour"
|
|
|
|
|
|
|
|
def perform(*args)
|
|
|
|
fix_etablissement_with_dossier
|
|
|
|
fix_etablissement_with_champs
|
|
|
|
end
|
|
|
|
|
|
|
|
def fix_etablissement_with_dossier
|
|
|
|
Etablissement.joins(:dossier).where(adresse: nil).find_each do |etablissement|
|
|
|
|
begin
|
|
|
|
procedure_id = etablissement.dossier.procedure.id
|
|
|
|
|
|
|
|
APIEntrepriseService.update_etablissement_from_degraded_mode(etablissement, procedure_id)
|
|
|
|
rescue => e
|
|
|
|
Sentry.capture_exception(e)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def fix_etablissement_with_champs
|
|
|
|
Etablissement.joins(:champ).where(adresse: nil).find_each do |etablissement|
|
|
|
|
begin
|
|
|
|
procedure_id = etablissement.champ.procedure.id
|
|
|
|
|
|
|
|
APIEntrepriseService.update_etablissement_from_degraded_mode(etablissement, procedure_id)
|
|
|
|
rescue => e
|
|
|
|
Sentry.capture_exception(e)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|