Merge pull request #1578 from betagouv/frederic/fix_1545-send_missed_accuse_de_reception

[Fix #1545] Rake task to send accusés de réception that were missed
This commit is contained in:
Frederic Merizen 2018-03-09 18:42:35 +01:00 committed by GitHub
commit 75f89e4f09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,26 @@
namespace :'2018_03_08_send_missing_accuse_reception' do
task send: :environment do
# Send accusés de réception that were missed because of #1510
#
# The bug was introduced in production with the 2018-03-01-01 release
# and fixed with the 2018-03-05-03 release.
#
# `bug_date` and `fix_date` were determined empirically by looking at the release times,
# and checking for dossiers with a missing accusé de réception.
bug_date = DateTime.new(2018, 3, 1, 9, 50)
fix_date = DateTime.new(2018, 3, 5, 18, 40)
# Only send the accusé for dossiers that are still en construction.
# For dossiers that have moved on, other mails have been sent since, and a late
# accusé de réception would add more confusion than its worth
problem_dossiers = Dossier.where(en_construction_at: bug_date..fix_date)
problem_dossiers.find_each do |dossier|
template = dossier.procedure.initiated_mail_template
date_depot = dossier.en_construction_at.in_time_zone("Paris").strftime('%d/%m/%Y à %H:%M')
body_prefix = "<p>Suite à une difficulté technique, veuillez recevoir par la présente laccusé de réception pour votre dossier déposé le #{date_depot}.<br>Léquipe demarches-simplifiees.fr vous présente ses excuses pour la gène occasionnée.</p><hr>\n"
template.body = body_prefix + template.body
NotificationMailer.send_notification(dossier, template).deliver_now!
end
end
end