From 931fd2130ad029b339619e0e60bc963e1040c2c8 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 21 Jul 2023 16:39:56 +0200 Subject: [PATCH] =?UTF-8?q?fix(dossier):=20purge=20motivations=20on=20doss?= =?UTF-8?q?iers=20non=20termin=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...purge_motivation_dossiers_not_termine.rake | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/tasks/deployment/20230721142825_purge_motivation_dossiers_not_termine.rake diff --git a/lib/tasks/deployment/20230721142825_purge_motivation_dossiers_not_termine.rake b/lib/tasks/deployment/20230721142825_purge_motivation_dossiers_not_termine.rake new file mode 100644 index 000000000..0e8e29c61 --- /dev/null +++ b/lib/tasks/deployment/20230721142825_purge_motivation_dossiers_not_termine.rake @@ -0,0 +1,21 @@ +namespace :after_party do + desc 'Deployment task: purge_motivation_dossiers_not_termine' + task purge_motivation_dossiers_not_termine: :environment do + puts "Running deploy task 'purge_motivation_dossiers_not_termine'" + + dossier_with_justificatif_motivation_ids = ActiveStorage::Attachment.where(name: 'justificatif_motivation').pluck(:record_id).uniq + dossiers = Dossier.where(id: dossier_with_justificatif_motivation_ids).state_not_termine + progress = ProgressReport.new(dossiers.count) + + dossiers.find_each do |dossier| + dossier.justificatif_motivation.purge_later + progress.inc + end + progress.finish + + # 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