Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions config/initializers/job_configurations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

@h-m-m h-m-m Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minute is not enough of a delay, based on https://gsa-tts.slack.com/archives/CMW9H0RFX/p1724077904549099?thread_ts=1722271455.385999&cid=CMW9H0RFX

Two bits is 25, so delaying for a bit must be ~12 minutes, eh 🤨?

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'

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions spec/config/initializers/job_configurations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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