From 878153c1389897851ef9a48551eb75ebfde89209 Mon Sep 17 00:00:00 2001 From: Joshua Drumm Date: Fri, 6 Sep 2024 16:17:50 -0400 Subject: [PATCH] Created two separate methods for failures and exhausted failures --- app/sidekiq/hca/ezr_submission_job.rb | 5 +- lib/form1010_ezr/service.rb | 31 ++++++++--- spec/lib/form1010_ezr/service_spec.rb | 78 +++++++++++++++------------ 3 files changed, 70 insertions(+), 44 deletions(-) diff --git a/app/sidekiq/hca/ezr_submission_job.rb b/app/sidekiq/hca/ezr_submission_job.rb index 42e2ae51aa9..649c2e423a1 100644 --- a/app/sidekiq/hca/ezr_submission_job.rb +++ b/app/sidekiq/hca/ezr_submission_job.rb @@ -12,9 +12,8 @@ class EzrSubmissionJob sidekiq_options retry: 14 sidekiq_retries_exhausted do |msg, _e| - Form1010Ezr::Service.new(nil).log_submission_failure( - decrypt_form(msg['args'][0]), - retries_exhausted: true + Form1010Ezr::Service.new(nil).log_exhausted_submission_failure( + decrypt_form(msg['args'][0]) ) end diff --git a/lib/form1010_ezr/service.rb b/lib/form1010_ezr/service.rb index 49d9233c7eb..837775326f3 100644 --- a/lib/form1010_ezr/service.rb +++ b/lib/form1010_ezr/service.rb @@ -64,22 +64,41 @@ def submit_form(parsed_form) log_and_raise_error(e, parsed_form) end - def log_submission_failure(parsed_form, retries_exhausted: false) - StatsD.increment("#{Form1010Ezr::Service::STATSD_KEY_PREFIX}.failed#{'_wont_retry' if retries_exhausted}") + def log_submission_failure(parsed_form) + StatsD.increment("#{Form1010Ezr::Service::STATSD_KEY_PREFIX}.failed") if parsed_form.present? PersonalInformationLog.create!( data: parsed_form, - error_class: "Form1010Ezr Failed#{'WontRetry' if retries_exhausted}" + error_class: 'Form1010Ezr Failed' ) - failure_message = "1010EZR #{'total ' if retries_exhausted}failure" + failure_message = '1010EZR failure' log_message_to_sentry( - failure_message, + '1010EZR failure', :error, veteran_initials(parsed_form), - ezr: retries_exhausted ? :total_failure : :failure + ezr: :failure + ) + end + end + + # When a submission runs out of retry attempts + def log_exhausted_submission_failure(parsed_form) + StatsD.increment("#{Form1010Ezr::Service::STATSD_KEY_PREFIX}.failed_wont_retry") + + if parsed_form.present? + PersonalInformationLog.create!( + data: parsed_form, + error_class: 'Form1010Ezr FailedWontRetry' + ) + + log_message_to_sentry( + '1010EZR total failure', + :error, + veteran_initials(parsed_form), + ezr: :total_failure ) end end diff --git a/spec/lib/form1010_ezr/service_spec.rb b/spec/lib/form1010_ezr/service_spec.rb index aefb3bc4c9f..de2d526a59d 100644 --- a/spec/lib/form1010_ezr/service_spec.rb +++ b/spec/lib/form1010_ezr/service_spec.rb @@ -175,48 +175,56 @@ def expect_personal_info_log(message) end context "when 'parsed_form' is present" do - context "when 'retries_exhausted' is false" do - it "increments StatsD, creates a 'PersonalInformationLog' record, and logs a failure message to sentry" do - # The names for these errors will not include 'total' or 'wont_retry' as they are not for total failures - allow(StatsD).to receive(:increment) - expect(StatsD).to receive(:increment).with('api.1010ezr.failed') - expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with( - '1010EZR failure', - :error, - { - first_initial: 'F', - middle_initial: 'M', - last_initial: 'Z' - }, - ezr: :failure - ) + it "increments StatsD, creates a 'PersonalInformationLog' record, and logs a failure message to sentry" do + allow(StatsD).to receive(:increment) + expect(StatsD).to receive(:increment).with('api.1010ezr.failed') + expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with( + '1010EZR failure', + :error, + { + first_initial: 'F', + middle_initial: 'M', + last_initial: 'Z' + }, + ezr: :failure + ) - described_class.new(nil).log_submission_failure(form) + described_class.new(nil).log_submission_failure(form) - expect_personal_info_log('Form1010Ezr Failed') - end + expect_personal_info_log('Form1010Ezr Failed') end + end + end - context "when 'retries_exhausted' is true" do - it "increments StatsD, creates a 'PersonalInformationLog' record, and logs a TOTAL failure message to sentry" do - allow(StatsD).to receive(:increment) + describe '#log_exhausted_submission_failure' do + context "when 'parsed_form' is not present" do + it 'only increments StatsD' do + allow(StatsD).to receive(:increment) + expect(StatsD).to receive(:increment).with('api.1010ezr.failed_wont_retry') - expect(StatsD).to receive(:increment).with('api.1010ezr.failed_wont_retry') - expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with( - '1010EZR total failure', - :error, - { - first_initial: 'F', - middle_initial: 'M', - last_initial: 'Z' - }, - ezr: :total_failure - ) + described_class.new(nil).log_exhausted_submission_failure(nil) + end + end - described_class.new(nil).log_submission_failure(form, retries_exhausted: true) + context "when 'parsed_form' is present" do + it "increments StatsD, creates a 'PersonalInformationLog' record, and logs a failure message to sentry" do + allow(StatsD).to receive(:increment) - expect_personal_info_log('Form1010Ezr FailedWontRetry') - end + expect(StatsD).to receive(:increment).with('api.1010ezr.failed_wont_retry') + expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with( + '1010EZR total failure', + :error, + { + first_initial: 'F', + middle_initial: 'M', + last_initial: 'Z' + }, + ezr: :total_failure + ) + + described_class.new(nil).log_exhausted_submission_failure(form) + + expect_personal_info_log('Form1010Ezr FailedWontRetry') end end end