2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-13 17:59:33 +01:00
|
|
|
class NotificationService
|
|
|
|
class << self
|
2023-05-09 11:32:35 +02:00
|
|
|
SPREAD_DURATION = 2.hours
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
def send_instructeur_email_notification
|
2023-05-09 11:32:35 +02:00
|
|
|
instructeurs = Instructeur
|
2021-12-09 11:13:29 +01:00
|
|
|
.includes(assign_to: [:procedure])
|
2020-02-27 11:09:19 +01:00
|
|
|
.where(assign_tos: { daily_email_notifications_enabled: true })
|
2019-03-13 17:59:33 +01:00
|
|
|
|
2023-05-09 11:32:35 +02:00
|
|
|
instructeurs.in_batches.each_record do |instructeur|
|
|
|
|
data = instructeur.email_notification_data
|
|
|
|
|
|
|
|
next if data.empty?
|
|
|
|
|
|
|
|
wait = rand(0..SPREAD_DURATION)
|
2019-03-13 17:59:33 +01:00
|
|
|
|
2023-05-09 11:32:35 +02:00
|
|
|
InstructeurMailer.send_notifications(instructeur, data).deliver_later(wait:)
|
|
|
|
end
|
2019-03-13 17:59:33 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|