fix(job): Cron::WeeklyOverviewJob simplified and respect dolist API rate limiting
This commit is contained in:
parent
f8f14830a6
commit
43613009d6
2 changed files with 20 additions and 15 deletions
|
@ -1,13 +1,16 @@
|
|||
class Cron::WeeklyOverviewJob < Cron::CronJob
|
||||
self.schedule_expression = "every monday at 7 am"
|
||||
|
||||
def perform(*args)
|
||||
def perform
|
||||
# Feature flipped to avoid mails in staging due to unprocessed dossier
|
||||
if Rails.application.config.ds_weekly_overview
|
||||
Instructeur.all
|
||||
.map { |instructeur| [instructeur, instructeur.last_week_overview] }
|
||||
.reject { |_, overview| overview.nil? }
|
||||
.each { |instructeur, _| InstructeurMailer.last_week_overview(instructeur).deliver_later }
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue