From 45180a5d9928e263f63d42624f170bd3fdb7efcd Mon Sep 17 00:00:00 2001 From: "Howard M. Miller" <3620291+h-m-m@users.noreply.github.com> Date: Mon, 5 Aug 2024 13:47:20 -0400 Subject: [PATCH] Stagger weekly Cloudwatch-heavy report jobs to not hit rate limits The specific times and order in which the reports run were not picked with a specific reason in mind. Feel free to adjust the times as appropriate. changelog: Internal, Reporting, Stagger Cloudwatch-heavy report jobs so they don't hit rate limits --- config/initializers/job_configurations.rb | 6 ++++-- spec/config/initializers/job_configurations_spec.rb | 8 ++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/config/initializers/job_configurations.rb b/config/initializers/job_configurations.rb index 3b5a81fc33b..0cbc563501c 100644 --- a/config/initializers/job_configurations.rb +++ b/config/initializers/job_configurations.rb @@ -7,6 +7,8 @@ cron_24h_1am = '0 1 * * *' # 1am UTC is 8pm EST/9pm EDT gpo_cron_24h = '0 10 * * *' # 10am UTC is 5am EST/6am EDT cron_every_monday = 'every Monday at 0:00 UTC' # equivalent to '0 0 * * 1' +cron_every_monday_1am = 'every Monday at 1:00 UTC' # equivalent to '0 1 * * 1' +cron_every_monday_2am = 'every Monday at 2:00 UTC' # equivalent to '0 2 * * 1' if defined?(Rails::Console) Rails.logger.info 'job_configurations: console detected, skipping schedule' @@ -226,13 +228,13 @@ # Previous week's drop of report weekly_drop_off_report: { class: 'Reports::DropOffReport', - cron: cron_every_monday, + cron: cron_every_monday_1am, args: -> { [Time.zone.yesterday.end_of_day] }, }, # Previous week's protocols report weekly_protocols_report: { class: 'Reports::ProtocolsReport', - cron: cron_every_monday, + cron: cron_every_monday_2am, args: -> { [Time.zone.yesterday.end_of_day] }, }, }.compact diff --git a/spec/config/initializers/job_configurations_spec.rb b/spec/config/initializers/job_configurations_spec.rb index dcc6e8632a9..bcd432593e1 100644 --- a/spec/config/initializers/job_configurations_spec.rb +++ b/spec/config/initializers/job_configurations_spec.rb @@ -25,13 +25,9 @@ now = Time.zone.now next_time = Fugit.parse(report[:cron]).next_time - expect(next_time.utc > now.utc.end_of_week). - to be(true), "Expected #{job_name} to next run after the end of this week" expect(next_time.utc). - to be_within(1).of(now.utc.end_of_week), <<~EOS.squish - Expected #{job_name} to run soon after the end of week, - so CONUS 'yesterday' and UTC 'yesterday' will never be different - EOS + to be_within(2.hours).of(now.utc.end_of_week) + expect(next_time.utc).to be > now.utc.end_of_week end end end