diff --git a/lib/tasks/ds/destroy_expired_dossiers_mae.rake b/lib/tasks/ds/destroy_expired_dossiers_mae.rake new file mode 100644 index 000000000..67d44858f --- /dev/null +++ b/lib/tasks/ds/destroy_expired_dossiers_mae.rake @@ -0,0 +1,16 @@ +namespace :ds do + desc 'DS task: destroy_expired_dossiers_mae' + task destroy_expired_dossiers_mae: :environment do + dossiers = Dossier.state_termine + .where("termine_close_to_expiration_notice_sent_at + INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: '30 days' }) + .joins(:groupe_instructeur) + .where(groupe_instructeur: { procedure_id: [47787, 47844, 47478, 47865] }) + progress = ProgressReport.new(dossiers.count) + + dossiers.find_each do |dossier| + dossier.expired_keep_track_and_destroy! + progress.inc + end + progress.finish + end +end