task(dossiers): delete MAE procedures expired dossiers

This commit is contained in:
Paul Chavard 2021-11-03 16:21:20 +01:00
parent 14d3956419
commit e4317e8c7e

View file

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