amelioration(email.resume_hebdomadaire): envoie le mail a 4h du matin sur une periode de 3h

tech(
Co-authored-by: Colin Darie <colin@darie.eu>
This commit is contained in:
Martin 2023-06-26 15:23:59 +02:00
parent 18096a709b
commit a0ceee96bd
3 changed files with 5 additions and 8 deletions

View file

@ -1,16 +1,13 @@
class Cron::WeeklyOverviewJob < Cron::CronJob
self.schedule_expression = "every monday at 7 am"
self.schedule_expression = "every monday at 4 am"
def perform
# Feature flipped to avoid mails in staging due to unprocessed dossier
return unless Rails.application.config.ds_weekly_overview
Instructeur.find_each do |instructeur|
# NOTE: it's not exactly accurate because rate limit is not shared between jobs processes
Dolist::API.sleep_until_limit_reset if Dolist::API.near_rate_limit?
# mailer won't send anything if overview if empty
InstructeurMailer.last_week_overview(instructeur)&.deliver_later
InstructeurMailer.last_week_overview(instructeur)&.deliver_later(wait: rand(0..3.hours))
end
end
end

View file

@ -23,10 +23,10 @@ class MailRateLimiter
end
def current_window_expired?
@current_window[:started_at] + @window <= Time.zone.now.utc
(@current_window[:started_at] + @window).past?
end
def current_window_full?
@current_window[:sent] == @limit
@current_window[:sent] >= @limit
end
end

View file

@ -17,7 +17,7 @@ describe MailRateLimiter do
it 'renews current_window when it expires' do
rate_limiter.send_with_delay(mail)
Timecop.travel(window + 1.second) do
travel_to(Time.current + window + 1.second) do
rate_limiter.send_with_delay(mail)
expect(rate_limiter.current_window[:sent]).to eq(1)
end