Compare commits

...

4 commits

Author SHA1 Message Date
LeSim
d3cd5b6942
Merge pull request #9017 from colinux/spread-instructeur-summary-email
Email: étale un peu dans le temps l'envoi des rapports aux instructeurs pour éviter le quota Dolist
2023-05-10 10:03:47 +00:00
LeSim
a9c0df4d11
Merge pull request #9020 from demarches-simplifiees/add_administration_header
Ajouter des bannières visant soit les instructeurs / admins soit les usagers
2023-05-10 10:03:31 +00:00
simon lehericey
19c9d12e71 add banner for administrations / usagers 2023-05-09 17:14:23 +02:00
Colin Darie
f7029615a9
refactor(email): spread sending of instructeur digest emails over time
On envoi parfois plus de 20K mails, ce qui pose des problèmes de délivrance
et quotas si on le fait d'un coup.
On étale donc un peu dans la durée ces envois pour pas limiter le dépassement
de quota.
2023-05-09 11:32:43 +02:00
4 changed files with 30 additions and 10 deletions

View file

@ -1,5 +1,5 @@
class Cron::InstructeurEmailNotificationJob < Cron::CronJob class Cron::InstructeurEmailNotificationJob < Cron::CronJob
self.schedule_expression = "from monday through friday at 10 am" self.schedule_expression = "from monday through friday at 9 am"
def perform(*args) def perform(*args)
NotificationService.send_instructeur_email_notification NotificationService.send_instructeur_email_notification

View file

@ -1,19 +1,21 @@
class NotificationService class NotificationService
class << self class << self
SPREAD_DURATION = 2.hours
def send_instructeur_email_notification def send_instructeur_email_notification
Instructeur instructeurs = Instructeur
.includes(assign_to: [:procedure]) .includes(assign_to: [:procedure])
.where(assign_tos: { daily_email_notifications_enabled: true }) .where(assign_tos: { daily_email_notifications_enabled: true })
.find_in_batches { |instructeurs| send_batch_of_instructeurs_email_notification(instructeurs) }
instructeurs.in_batches.each_record do |instructeur|
data = instructeur.email_notification_data
next if data.empty?
wait = rand(0..SPREAD_DURATION)
InstructeurMailer.send_notifications(instructeur, data).deliver_later(wait:)
end end
private
def send_batch_of_instructeurs_email_notification(instructeurs)
instructeurs
.map { |instructeur| [instructeur, instructeur.email_notification_data] }
.reject { |(_instructeur, data)| data.empty? }
.each { |(instructeur, data)| InstructeurMailer.send_notifications(instructeur, data).deliver_later }
end end
end end
end end

View file

@ -2,3 +2,13 @@
.site-banner.warning .site-banner.warning
.container .container
= sanitize(ENV['BANNER_MESSAGE']) = sanitize(ENV['BANNER_MESSAGE'])
- if ENV['ADMINISTRATION_BANNER_MESSAGE'].present? && instructeur_signed_in?
.site-banner.warning
.container
= sanitize(ENV['ADMINISTRATION_BANNER_MESSAGE'])
- if ENV['USAGER_BANNER_MESSAGE'].present? && !instructeur_signed_in?
.site-banner.warning
.container
= sanitize(ENV['USAGER_BANNER_MESSAGE'])

View file

@ -188,3 +188,11 @@ SMTP_AUTHENTICATION="plain"
SENDMAIL_ENABLED="disabled" SENDMAIL_ENABLED="disabled"
SENDMAIL_LOCATION="/usr/sbin/sendmail" SENDMAIL_LOCATION="/usr/sbin/sendmail"
SENDMAIL_ARGUMENTS="-i" SENDMAIL_ARGUMENTS="-i"
# Various banner for important messages
# for all users
BANNER_MESSAGE=""
# for instructeurs and admins only
ADMINISTRATION_BANNER_MESSAGE=""
# for usager only
USAGER_BANNER_MESSAGE=""