From 75985254bd5a1ceba0e107f7242b51c01f7d6239 Mon Sep 17 00:00:00 2001 From: Joshua Drumm Date: Mon, 9 Sep 2024 13:45:13 -0400 Subject: [PATCH] Refactored code to extend SentryLogging instead of including it --- app/sidekiq/hca/ezr_submission_job.rb | 8 +++++--- spec/sidekiq/hca/ezr_submission_job_spec.rb | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/sidekiq/hca/ezr_submission_job.rb b/app/sidekiq/hca/ezr_submission_job.rb index 5ded4bd4482..41010cff4e3 100644 --- a/app/sidekiq/hca/ezr_submission_job.rb +++ b/app/sidekiq/hca/ezr_submission_job.rb @@ -6,10 +6,12 @@ module HCA class EzrSubmissionJob include Sidekiq::Job - include SentryLogging + extend SentryLogging VALIDATION_ERROR = HCA::SOAPParser::ValidationError STATSD_KEY_PREFIX = 'api.1010ezr' + # 14 retries was decided on because it's the closest to a 24-hour time span based on + # Sidekiq's backoff formula: https://github.com/sidekiq/sidekiq/wiki/Error-Handling#automatic-job-retry sidekiq_options retry: 14 sidekiq_retries_exhausted do |msg, _e| @@ -23,7 +25,7 @@ class EzrSubmissionJob error_class: 'Form1010Ezr FailedWontRetry' ) - new.log_message_to_sentry( + log_message_to_sentry( '1010EZR total failure', :error, Form1010Ezr::Service.new(nil).veteran_initials(parsed_form), @@ -43,7 +45,7 @@ def perform(encrypted_form, user_uuid) Form1010Ezr::Service.new(user).submit_sync(parsed_form) rescue VALIDATION_ERROR => e Form1010Ezr::Service.new(nil).log_submission_failure(parsed_form) - log_exception_to_sentry(e) + self.class.log_exception_to_sentry(e) rescue StatsD.increment("#{STATSD_KEY_PREFIX}.async.retries") raise diff --git a/spec/sidekiq/hca/ezr_submission_job_spec.rb b/spec/sidekiq/hca/ezr_submission_job_spec.rb index 03b93b78dce..ae93a87c7f6 100644 --- a/spec/sidekiq/hca/ezr_submission_job_spec.rb +++ b/spec/sidekiq/hca/ezr_submission_job_spec.rb @@ -34,7 +34,7 @@ described_class.within_sidekiq_retries_exhausted_block(msg) do expect(StatsD).to receive(:increment).with('api.1010ezr.failed_wont_retry') - expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with( + expect(described_class).to receive(:log_message_to_sentry).with( '1010EZR total failure', :error, { @@ -73,7 +73,7 @@ # of the 'Form1010Ezr::Service', we need to stub out a new instance of the service allow(Form1010Ezr::Service).to receive(:new).with(nil).once.and_return(ezr_service) - expect_any_instance_of(HCA::EzrSubmissionJob).to receive(:log_exception_to_sentry).with(error) + expect(HCA::EzrSubmissionJob).to receive(:log_exception_to_sentry).with(error) expect(ezr_service).to receive(:log_submission_failure).with( form )