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
16 changes: 8 additions & 8 deletions config/initializers/job_configurations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -211,23 +211,23 @@
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: {
class: 'Reports::FraudMetricsReport',
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
Expand Down
24 changes: 24 additions & 0 deletions spec/config/initializers/job_configurations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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