fix(dossier): purge motivations on dossiers non terminé

This commit is contained in:
Paul Chavard 2023-07-21 16:39:56 +02:00
parent 4bc8b23a19
commit 931fd2130a

View file

@ -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