Skip to content

Commit

Permalink
Refactored code to extend SentryLogging instead of including it
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshingYou1 committed Sep 9, 2024
1 parent 9162c50 commit 7598525
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions app/sidekiq/hca/ezr_submission_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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),
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/sidekiq/hca/ezr_submission_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit 7598525

Please sign in to comment.