Skip to content

Commit

Permalink
Rescue DB errors when updating appeal form status
Browse files Browse the repository at this point in the history
- add rescus to base class
- add tests to each subclass
  • Loading branch information
kayline committed Nov 18, 2024
1 parent 70ac62b commit d356683
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SavedClaimStatusUpdaterJob
SECONDARY_FORM_ATTRIBUTES_TO_STORE = %w[status detail updated_at].freeze

def perform
return unless enabled? && records_to_update.present?
return unless should_perform?

StatsD.increment("#{statsd_prefix}.processing_records", records_to_update.size)

Expand Down Expand Up @@ -91,6 +91,13 @@ def enabled?
raise Common::Exceptions::NotImplemented
end

def should_perform?
enabled? && records_to_update.present?
rescue => e
StatsD.increment("#{statsd_prefix}.error")
Rails.logger.error("#{log_prefix} error", { message: e.message })
end

def decision_review_service
@service ||= DecisionReviewV1::Service.new
end
Expand Down
16 changes: 16 additions & 0 deletions spec/sidekiq/decision_review/hlr_status_updater_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@
.exactly(1).time
end
end

context 'Retrieving SavedClaim records fails' do
before do
allow(SavedClaim::HigherLevelReview).to receive(:where).and_raise(ActiveRecord::ConnectionTimeoutError)
allow(Rails.logger).to receive(:error)
end

it 'rescues the error and logs' do
subject.new.perform

expect(Rails.logger).to have_received(:error)
.with('DecisionReview::SavedClaimHlrStatusUpdaterJob error', anything)
expect(StatsD).to have_received(:increment)
.with('worker.decision_review.saved_claim_hlr_status_updater.error').once
end
end
end

context 'with flag disabled' do
Expand Down
16 changes: 16 additions & 0 deletions spec/sidekiq/decision_review/nod_status_updater_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,22 @@
end
end

context 'Retrieving SavedClaim records fails' do
before do
allow(SavedClaim::NoticeOfDisagreement).to receive(:where).and_raise(ActiveRecord::ConnectionTimeoutError)
allow(Rails.logger).to receive(:error)
end

it 'rescues the error and logs' do
subject.new.perform

expect(Rails.logger).to have_received(:error)
.with('DecisionReview::SavedClaimNodStatusUpdaterJob error', anything)
expect(StatsD).to have_received(:increment)
.with('worker.decision_review.saved_claim_nod_status_updater.error').once
end
end

context 'an error occurs while processing' do
before do
SavedClaim::NoticeOfDisagreement.create(guid: SecureRandom.uuid, form: '{}')
Expand Down
16 changes: 16 additions & 0 deletions spec/sidekiq/decision_review/sc_status_updater_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,22 @@
end
end

context 'Retrieving SavedClaim records fails' do
before do
allow(SavedClaim::SupplementalClaim).to receive(:where).and_raise(ActiveRecord::ConnectionTimeoutError)
allow(Rails.logger).to receive(:error)
end

it 'rescues the error and logs' do
subject.new.perform

expect(Rails.logger).to have_received(:error)
.with('DecisionReview::SavedClaimScStatusUpdaterJob error', anything)
expect(StatsD).to have_received(:increment)
.with('worker.decision_review.saved_claim_sc_status_updater.error').once
end
end

context 'an error occurs while processing form, attachments, or secondary form' do
before do
SavedClaim::SupplementalClaim.create(guid: SecureRandom.uuid, form: '{}')
Expand Down

0 comments on commit d356683

Please sign in to comment.