-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9551 from colinux/etablissement-consolidate-task
Tech: tâche consolidant les établissements en mode dégradé d'une démarche donnée
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require Rails.root.join("lib", "tasks", "task_helper") | ||
|
||
namespace :etablissement do | ||
desc 'Immediately consolidate etablissements in degraded mode for a given procedure id' | ||
task update_from_degraded_mode: :environment do | ||
procedure_id = ENV.fetch("PROCEDURE_ID") | ||
|
||
# Logic from BackfillSiretDegradedModeJob | ||
# but without the wait of all dossiers queue. | ||
|
||
rake_puts "Consolidate dossiers" | ||
etablissements = Etablissement.joins(dossier: :revision).where(adresse: nil, dossier: { procedure_revisions: { procedure_id: } }) | ||
progress = ProgressReport.new(etablissements.count) | ||
|
||
etablissements.find_each do |etablissement| | ||
begin | ||
APIEntrepriseService.update_etablissement_from_degraded_mode(etablissement, procedure_id) | ||
rescue => e | ||
Sentry.capture_exception(e) | ||
rake_puts "Etablissement ##{etablissement.id}: #{e.message}" | ||
end | ||
|
||
progress.inc | ||
end | ||
progress.finish | ||
|
||
rake_puts "Consolidate champs SIRET" | ||
etablissements = Etablissement.joins(champ: { dossier: :revision }).where(adresse: nil, champ: { procedure_revisions: { procedure_id: } }) | ||
progress = ProgressReport.new(etablissements.count) | ||
|
||
etablissements.find_each do |etablissement| | ||
begin | ||
APIEntrepriseService.update_etablissement_from_degraded_mode(etablissement, procedure_id) | ||
rescue => e | ||
Sentry.capture_exception(e) | ||
rake_puts "Etablissement ##{etablissement.id}: #{e.message}" | ||
end | ||
|
||
progress.inc | ||
end | ||
|
||
progress.finish | ||
end | ||
end |