Skip to content

Commit

Permalink
Vebt 765 - Modify BDN generation to account for holidays (#19641)
Browse files Browse the repository at this point in the history
* Skip holidays for ClearDeactivatedBdns periodic job

* Account for holidays for ingress jobs

* Add comment detailing ingress job skips on holidays

* Revert previous change from different job

* Add rspec test for holidays

* Add codeowners for rspec file

* Add all VYE scripts to holiday skipping logic

* Remove empty PurgeStaleVerifications method from Sundown Sweep

* Remove PurgeStaleVerifications from sundown sweep spec

* Realphabetize codeowner file

* Fix relative import error

* Remove duplicate import

* Remove reference to purge stale verifications

* Move holidays logic into VYE scripts

* Add holidays logic testing to rspec

* Move holidays logic to cloud transfer

* Fix linting errors
  • Loading branch information
alexchan-va authored Dec 16, 2024
1 parent 8a87d36 commit 7ea8d81
Show file tree
Hide file tree
Showing 19 changed files with 279 additions and 116 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,7 @@ spec/lib/pdf_info/metadata_spec.rb @department-of-veterans-affairs/va-api-engine
spec/lib/pdf_utilities @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/pension_burial @department-of-veterans-affairs/mbs-core-team @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/pension21p527ez/pension_military_information_spec.rb @department-of-veterans-affairs/pension-and-burials @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/periodic_jobs_spec.rb @department-of-veterans-affairs/govcio-vfep-codereviewers @department-of-veterans-affairs/backend-review-group
spec/lib/preneeds @department-of-veterans-affairs/mbs-core-team @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/post911_sob @department-of-veterans-affairs/govcio-vfep-codereviewers @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/rx @department-of-veterans-affairs/vfs-mhv-medications
Expand Down
6 changes: 3 additions & 3 deletions lib/periodic_jobs.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'holidays'

# @see https://crontab.guru/
# @see https://en.wikipedia.org/wiki/Cron
PERIODIC_JOBS = lambda { |mgr| # rubocop:disable Metrics/BlockLength
Expand Down Expand Up @@ -249,10 +251,8 @@
# Daily 0000 hrs job for Vye: performs ingress of state from BDN & TIMS.
mgr.register('15 00 * * 1-5', 'Vye::MidnightRun::IngressBdn')
mgr.register('45 03 * * 1-5', 'Vye::MidnightRun::IngressTims')

# Daily 0600 hrs job for Vye: activates ingressed state, and egresses the changes for the day.
mgr.register('45 05 * * 1-5', 'Vye::DawnDash')

# Daily job for Vye: clears deactivated BDNs every evening.
# Daily 1900 job for Vye: clears deactivated BDNs every evening.
mgr.register('00 19 * * 1-5', 'Vye::SundownSweep')
}
2 changes: 2 additions & 0 deletions modules/vye/app/sidekiq/vye/dawn_dash/activate_bdn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class ActivateBdn
sidekiq_options retry: 0

def perform
return if Vye::CloudTransfer.holiday?

BdnClone.activate_injested!
EgressUpdates.perform_async
end
Expand Down
2 changes: 2 additions & 0 deletions modules/vye/app/sidekiq/vye/dawn_dash/egress_updates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class EgressUpdates
sidekiq_options retry: 0

def perform
return if Vye::CloudTransfer.holiday?

Vye::BatchTransfer::EgressFiles.address_changes_upload
Vye::BatchTransfer::EgressFiles.direct_deposit_upload
Vye::BatchTransfer::EgressFiles.verification_upload
Expand Down
2 changes: 2 additions & 0 deletions modules/vye/app/sidekiq/vye/midnight_run/ingress_bdn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class IngressBdn
sidekiq_options retry: 5

def perform
return if Vye::CloudTransfer.holiday?

bdn_clone = Vye::BdnClone.create!(transact_date: Time.zone.today)
bdn_clone_id = bdn_clone.id

Expand Down
2 changes: 2 additions & 0 deletions modules/vye/app/sidekiq/vye/midnight_run/ingress_tims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class IngressTims
sidekiq_options retry: 0

def perform
return if Vye::CloudTransfer.holiday?

Vye::PendingDocument.delete_all

chunks = BatchTransfer::TimsChunk.build_chunks
Expand Down
1 change: 0 additions & 1 deletion modules/vye/app/sidekiq/vye/sundown_sweep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class SundownSweep
def perform
ClearDeactivatedBdns.perform_async
DeleteProcessedS3Files.perform_async
PurgeStaleVerifications.perform_async
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class ClearDeactivatedBdns
include Sidekiq::Worker

def perform
return if Vye::CloudTransfer.holiday?

logger.info('Beginning: delete deactivated bdns')
Vye::CloudTransfer.delete_inactive_bdns
logger.info('Finishing: delete deactivated bdns')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class SundownSweep
class DeleteProcessedS3Files
include Sidekiq::Worker
def perform
return if Vye::CloudTransfer.holiday?

logger.info('Beginning: remove_aws_files_from_s3_buckets')
Vye::CloudTransfer.remove_aws_files_from_s3_buckets
logger.info('Finishing: remove_aws_files_from_s3_buckets')
Expand Down

This file was deleted.

4 changes: 4 additions & 0 deletions modules/vye/lib/concerns/vye/cloud_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def s3_client
Aws::S3::Client.new(**credentials)
end

def holiday?
Holidays.on(Time.zone.today, :us, :observed).any?
end

def tmp_dir
result = Rails.root / "tmp/vye/#{SecureRandom.uuid}"
result.mkpath
Expand Down
46 changes: 36 additions & 10 deletions modules/vye/spec/sidekiq/vye/dawn_dash/activate_bdn_spec.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,48 @@
# frozen_string_literal: true

require 'rails_helper'
require Vye::Engine.root / 'spec/rails_helper'
require 'timecop'

describe Vye::DawnDash::ActivateBdn, type: :worker do
describe Vye::SundownSweep::DeleteProcessedS3Files, type: :worker do
before do
Sidekiq::Worker.clear_all
Sidekiq::Job.clear_all
end

it 'enqueues child jobs' do
expect(Vye::BdnClone).to receive(:activate_injested!)
context 'when it is not a holiday' do
before do
Timecop.freeze(Time.zone.local(2024, 7, 2)) # Regular work day
end

expect do
described_class.perform_async
end.to change { Sidekiq::Worker.jobs.size }.by(1)
after do
Timecop.return
end

described_class.drain
it 'checks the existence of described_class' do
expect(Vye::CloudTransfer).to receive(:remove_aws_files_from_s3_buckets)

expect(Vye::DawnDash::EgressUpdates).to have_enqueued_sidekiq_job
expect do
described_class.perform_async
end.to change { Sidekiq::Worker.jobs.size }.by(1)

described_class.drain
end
end

context 'when it is a holiday' do
before do
Timecop.freeze(Time.zone.local(2024, 7, 4)) # Independence Day
end

after do
Timecop.return
end

it 'does not process S3 files' do
expect(Vye::CloudTransfer).not_to receive(:remove_aws_files_from_s3_buckets)

expect do
described_class.new.perform
end.not_to(change { Sidekiq::Worker.jobs.size })
end
end
end
50 changes: 41 additions & 9 deletions modules/vye/spec/sidekiq/vye/dawn_dash/egress_updates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,54 @@

require 'rails_helper'
require Vye::Engine.root / 'spec/rails_helper'
require 'timecop'

describe Vye::DawnDash::EgressUpdates, type: :worker do
before do
Sidekiq::Worker.clear_all
end

it 'checks the existence of described_class' do
expect(Vye::BatchTransfer::EgressFiles).to receive(:address_changes_upload)
expect(Vye::BatchTransfer::EgressFiles).to receive(:direct_deposit_upload)
expect(Vye::BatchTransfer::EgressFiles).to receive(:verification_upload)
expect(Vye::BdnClone).to receive(:clear_export_ready!)
context 'when it is not a holiday' do
before do
Timecop.freeze(Time.zone.local(2024, 7, 2)) # Regular work day
end

expect do
described_class.perform_async
end.to change { Sidekiq::Worker.jobs.size }.by(1)
after do
Timecop.return
end

described_class.drain
it 'checks the existence of described_class' do
expect(Vye::BatchTransfer::EgressFiles).to receive(:address_changes_upload)
expect(Vye::BatchTransfer::EgressFiles).to receive(:direct_deposit_upload)
expect(Vye::BatchTransfer::EgressFiles).to receive(:verification_upload)
expect(Vye::BdnClone).to receive(:clear_export_ready!)

expect do
described_class.perform_async
end.to change { Sidekiq::Worker.jobs.size }.by(1)

described_class.drain
end
end

context 'when it is a holiday' do
before do
Timecop.freeze(Time.zone.local(2024, 7, 4)) # Independence Day
end

after do
Timecop.return
end

it 'does not process egress updates' do
expect(Vye::BatchTransfer::EgressFiles).not_to receive(:address_changes_upload)
expect(Vye::BatchTransfer::EgressFiles).not_to receive(:direct_deposit_upload)
expect(Vye::BatchTransfer::EgressFiles).not_to receive(:verification_upload)
expect(Vye::BdnClone).not_to receive(:clear_export_ready!)

expect do
described_class.new.perform
end.not_to(change { Sidekiq::Worker.jobs.size })
end
end
end
44 changes: 36 additions & 8 deletions modules/vye/spec/sidekiq/vye/midnight_run/ingress_bdn_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'rails_helper'
require Vye::Engine.root / 'spec/rails_helper'
require 'timecop'

describe Vye::MidnightRun::IngressBdn, type: :worker do
let(:bdn_clone) { FactoryBot.create(:vye_bdn_clone_base) }
Expand All @@ -18,16 +19,43 @@
Sidekiq::Job.clear_all
end

it 'checks the existence of described_class' do
expect(Vye::BdnClone).to receive(:create!).and_return(bdn_clone)
expect(Vye::BatchTransfer::BdnChunk).to receive(:build_chunks).and_return(chunks)
context 'when it is not a holiday' do
before do
Timecop.freeze(Time.zone.local(2024, 7, 2)) # Regular work day
end

after do
Timecop.return
end

it 'checks the existence of described_class' do
expect(Vye::BdnClone).to receive(:create!).and_return(bdn_clone)
expect(Vye::BatchTransfer::BdnChunk).to receive(:build_chunks).and_return(chunks)

expect do
described_class.perform_async
end.to change { Sidekiq::Worker.jobs.size }.by(1)
expect do
described_class.perform_async
end.to change { Sidekiq::Worker.jobs.size }.by(1)

described_class.drain
described_class.drain

expect(Vye::MidnightRun::IngressBdnChunk).to have_enqueued_sidekiq_job.exactly(5).times
end
end

expect(Vye::MidnightRun::IngressBdnChunk).to have_enqueued_sidekiq_job.exactly(5).times
context 'when it is a holiday' do
before do
Timecop.freeze(Time.zone.local(2024, 7, 4)) # Independence Day
end

after do
Timecop.return
end

it 'does not process BDNs' do
expect(Vye::BdnClone).not_to receive(:create!)
expect(Vye::BatchTransfer::BdnChunk).not_to receive(:build_chunks)

described_class.new.perform
end
end
end
43 changes: 36 additions & 7 deletions modules/vye/spec/sidekiq/vye/midnight_run/ingress_tims_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'rails_helper'
require Vye::Engine.root / 'spec/rails_helper'
require 'timecop'

describe Vye::MidnightRun::IngressTims, type: :worker do
let(:chunks) do
Expand All @@ -17,15 +18,43 @@
Sidekiq::Job.clear_all
end

it 'checks the existence of described_class' do
expect(Vye::BatchTransfer::TimsChunk).to receive(:build_chunks).and_return(chunks)
context 'when it is not a holiday' do
before do
Timecop.freeze(Time.zone.local(2024, 7, 2)) # Regular work day
end

after do
Timecop.return
end

it 'checks the existence of described_class' do
expect(Vye::BatchTransfer::TimsChunk).to receive(:build_chunks).and_return(chunks)

expect do
described_class.perform_async
end.to change { Sidekiq::Worker.jobs.size }.by(1)
expect do
described_class.perform_async
end.to change { Sidekiq::Worker.jobs.size }.by(1)

described_class.drain
described_class.drain

expect(Vye::MidnightRun::IngressTimsChunk).to have_enqueued_sidekiq_job.exactly(5).times
end
end

expect(Vye::MidnightRun::IngressTimsChunk).to have_enqueued_sidekiq_job.exactly(5).times
context 'when it is a holiday' do
before do
Timecop.freeze(Time.zone.local(2024, 7, 4)) # Independence Day
end

after do
Timecop.return
end

it 'does not process TIMS' do
expect(Vye::BatchTransfer::TimsChunk).not_to receive(:build_chunks)

expect do
described_class.new.perform
end.not_to(change { Sidekiq::Worker.jobs.size })
end
end
end
Loading

0 comments on commit 7ea8d81

Please sign in to comment.