Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech: tâche consolidant les établissements en mode dégradé d'une démarche donnée #9551

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions lib/tasks/etablissement.rake
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