diff --git a/config/initializers/job_configurations.rb b/config/initializers/job_configurations.rb index c15b6af5f9d..e1e7e7fb71b 100644 --- a/config/initializers/job_configurations.rb +++ b/config/initializers/job_configurations.rb @@ -6,7 +6,7 @@ cron_24h = '0 0 * * *' 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_1w = '0 0 * * 0' +cron_every_monday = 'every Monday at 0:00 UTC' # equivalent to '0 0 * * 1' if defined?(Rails::Console) Rails.logger.info 'job_configurations: console detected, skipping schedule' @@ -211,11 +211,11 @@ cron: cron_24h, args: -> { [Time.zone.yesterday.end_of_day] }, }, - # Send weekly authentication reports to partners + # Send previous week's authentication reports to partners weekly_authentication_report: { class: 'Reports::AuthenticationReport', - cron: cron_1w, - args: -> { [Time.zone.now] }, + cron: cron_every_monday, + args: -> { [Time.zone.yesterday] }, }, # Send fraud metrics to Team Judy fraud_metrics_report: { @@ -223,11 +223,11 @@ cron: cron_24h, args: -> { [Time.zone.yesterday.end_of_day] }, }, - # Weekly drop of report - drop_off_report: { + # Previous week's drop of report + weekly_drop_off_report: { class: 'Reports::DropOffReport', - cron: cron_1w, - args: -> { [Time.zone.today] }, + cron: cron_every_monday, + args: -> { [Time.zone.yesterday] }, }, }.compact end diff --git a/spec/config/initializers/job_configurations_spec.rb b/spec/config/initializers/job_configurations_spec.rb index cb03410ce42..0ebf67e9a93 100644 --- a/spec/config/initializers/job_configurations_spec.rb +++ b/spec/config/initializers/job_configurations_spec.rb @@ -11,4 +11,28 @@ end end end + + describe 'weekly reporting' do + %w[drop_off_report authentication_report].each do |job_name| + it "schedules the #{job_name} to run after the end of the week with yesterday's date" do + report = GoodJob.configuration.cron[:"weekly_#{job_name}"] + expect(report[:class]).to eq("Reports::#{job_name.camelize}") + + freeze_time do + # Always passes the previous day as the argument + expect(report[:args].call).to eq([Time.zone.yesterday]) + + 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 + end + end + end + end end