diff --git a/config/initializers/job_configurations.rb b/config/initializers/job_configurations.rb index dc89d3f0dad..2695c547fb1 100644 --- a/config/initializers/job_configurations.rb +++ b/config/initializers/job_configurations.rb @@ -4,9 +4,10 @@ cron_12m = '0/12 * * * *' cron_1h = '0 * * * *' cron_24h = '0 0 * * *' +cron_24h_and_a_bit = '12 0 * * *' # 0000 UTC + 12 min, staggered from whatever else runs at 0000 UTC 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 = 'every Monday at 0:25 UTC' # equivalent to '25 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' @@ -181,7 +182,7 @@ # Send Identity Verification report to S3 identity_verification_report: { class: 'Reports::IdentityVerificationReport', - cron: cron_24h, + cron: cron_24h_and_a_bit, args: -> { [Time.zone.yesterday] }, }, # Refresh USPS auth tokens @@ -223,7 +224,7 @@ # Send fraud metrics to Team Judy fraud_metrics_report: { class: 'Reports::FraudMetricsReport', - cron: cron_24h, + cron: cron_24h_and_a_bit, args: -> { [Time.zone.yesterday.end_of_day] }, }, # Previous week's drop of report diff --git a/spec/config/initializers/job_configurations_spec.rb b/spec/config/initializers/job_configurations_spec.rb index bcd432593e1..b36d463d7cf 100644 --- a/spec/config/initializers/job_configurations_spec.rb +++ b/spec/config/initializers/job_configurations_spec.rb @@ -13,9 +13,10 @@ end describe 'weekly reporting' do - %w[drop_off_report authentication_report].each do |job_name| + %w[drop_off_report authentication_report protocols_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).to be, "Missing report weekly_#{job_name}" expect(report[:class]).to eq("Reports::#{job_name.camelize}") freeze_time do @@ -26,10 +27,23 @@ now = Time.zone.now next_time = Fugit.parse(report[:cron]).next_time expect(next_time.utc). - to be_within(2.hours).of(now.utc.end_of_week) + to be_within(2.hours + 1.minute).of(now.utc.end_of_week) expect(next_time.utc).to be > now.utc.end_of_week end end end + it 'has each report scheduled at a different time' do + next_times = freeze_time do + %w[drop_off_report authentication_report protocols_report].map do |job_name| + report = GoodJob.configuration.cron[:"weekly_#{job_name}"] + expect(report).to be, "Missing report weekly_#{job_name}" + expect(report[:class]).to eq("Reports::#{job_name.camelize}") + expect(report[:args].call).to eq([Time.zone.yesterday.end_of_day]) + Fugit.parse(report[:cron]).next_time.to_i + end + end + expect(next_times.count).to be(3) + expect(next_times.uniq.count).to be(3) + end end end