Skip to content

Commit

Permalink
Merge pull request #859 from trade-tariff/HOTT-2212-alert-when-missin…
Browse files Browse the repository at this point in the history
…g-files

HOTT-2212 Alert slack when missing CDS file
  • Loading branch information
jebw authored Nov 18, 2022
2 parents 1231981 + e0634dc commit ed37668
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
19 changes: 14 additions & 5 deletions app/workers/updates_synchronizer_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ def perform(check_for_todays_file = true, reapply_data_migrations = false)
TariffSynchronizer.download_cds

if check_for_todays_file &&
still_time_to_reschedule? &&
todays_file_has_not_yet_arrived?

self.class.perform_in(TRY_AGAIN_IN, true)
logger.info "Daily file missing, retrying at #{TRY_AGAIN_IN.from_now}"
todays_file_has_not_yet_arrived? &&
attempt_reschedule!
return
end

Expand Down Expand Up @@ -63,4 +60,16 @@ def migrate_data
require 'data_migrator' unless defined?(DataMigrator)
DataMigrator.migrate_up!(nil)
end

def attempt_reschedule!
if still_time_to_reschedule?
self.class.perform_in(TRY_AGAIN_IN, true)
logger.info "Daily file missing, retrying at #{TRY_AGAIN_IN.from_now}"
true
else
SlackNotifierService.call \
'Daily CDS file missing, max retry time passed - continuing without todays file'
false
end
end
end
18 changes: 18 additions & 0 deletions spec/workers/updates_synchronizer_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
before do
stub_const 'UpdatesSynchronizerWorker::CUT_OFF_TIME',
cut_off_time.strftime('%H:%M')

allow(SlackNotifierService).to receive(:call)
end

let(:service) { 'uk' }
Expand Down Expand Up @@ -108,6 +110,10 @@

it { expect(DataMigrator).not_to have_received(:migrate_up!) }
end

it 'does not notify Slack ETL channel' do
expect(SlackNotifierService).not_to have_received(:call)
end
end

context 'when after cut off time' do
Expand All @@ -128,6 +134,10 @@

it { expect(DataMigrator).to have_received(:migrate_up!).with(nil) }
end

it 'notifies Slack ETL channel' do
expect(SlackNotifierService).to have_received(:call).with(/CDS file missing/)
end
end

context 'when before cut off but check disabled' do
Expand All @@ -148,6 +158,10 @@

it { expect(DataMigrator).to have_received(:migrate_up!).with(nil) }
end

it 'does not notify Slack ETL channel' do
expect(SlackNotifierService).not_to have_received(:call)
end
end
end

Expand All @@ -171,6 +185,10 @@

it { expect(described_class.jobs).to be_empty }

it 'does not notify Slack ETL channel' do
expect(SlackNotifierService).not_to have_received(:call)
end

context 'with reapply_data_migrations option' do
subject(:perform) { described_class.new.perform(true, true) }

Expand Down

0 comments on commit ed37668

Please sign in to comment.