Skip to content

Commit

Permalink
[DBEX] refactor 0781 failure email logging & monitoring (#19122)
Browse files Browse the repository at this point in the history
  • Loading branch information
freeheeling authored Oct 30, 2024
1 parent cb94744 commit 6d947d0
Showing 1 changed file with 21 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ class Form0781DocumentUploadFailureEmail < Job
end

def perform(form526_submission_id)
submission = form526_submission(form526_submission_id)
submission = Form526Submission.find(form526_submission_id)

with_tracking('Form0781DocumentUploadFailureEmail', submission.saved_claim_id, form526_submission_id) do
send_notification_mailer(form526_submission_id)
send_notification_mailer(submission)
end
rescue => e
retryable_error_handler(e)
Expand All @@ -87,60 +87,41 @@ def retryable_error_handler(error)
raise error
end

def send_notification_mailer(form526_submission_id)
email_address = @form526_submission.veteran_email_address
first_name = @form526_submission.get_first_name
date_submitted = @form526_submission.format_creation_time_for_mailers
def send_notification_mailer(submission)
email_address = submission.veteran_email_address
first_name = submission.get_first_name
date_submitted = submission.format_creation_time_for_mailers

notify_service_bd = Settings.vanotify.services.benefits_disability
notify_client = VaNotify::Service.new(notify_service_bd.api_key)
template_id = notify_service_bd.template_id.form0781_upload_failure_notification_template_id

notify_response = notify_client.send_email(
email_address:,
template_id: mailer_template_id,
personalisation: {
first_name:,
date_submitted:
}
template_id:,
personalisation: { first_name:, date_submitted: }
)

log_mailer_dispatch(form526_submission_id, notify_response)
log_info = { form526_submission_id: submission.id, timestamp: Time.now.utc }

log_mailer_dispatch(submission, log_info, notify_response)
end

def log_mailer_dispatch(form526_submission_id, email_response = {})
def log_mailer_dispatch(submission, log_info, email_response = {})
StatsD.increment("#{STATSD_METRIC_PREFIX}.success")

log_info = { form526_submission_id:, timestamp: Time.now.utc }
Rails.logger.info('Form0781DocumentUploadFailureEmail notification dispatched', log_info)

cl = caller_locations.first
call_location = ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno)
zsf_monitor = ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE)

zsf_monitor.log_silent_failure_avoided(
log_info.merge(email_confirmation_id: email_response&.id),
@form526_submission&.user_account_id,
submission&.user_account_id,
call_location:
)
end

def form526_submission(form526_submission_id)
@form526_submission ||= Form526Submission.find(form526_submission_id)
end

def mailer_template_id
notify_service_bd.template_id.form0781_upload_failure_notification_template_id
end

def notify_client
@notify_client ||= VaNotify::Service.new(notify_service_bd.api_key)
end

def notify_service_bd
@notify_service_bd ||= Settings.vanotify.services.benefits_disability
end

def zsf_monitor
ZeroSilentFailures::Monitor.new(Form526Submission::ZSF_DD_TAG_SERVICE)
end

def call_location
cl = caller_locations.first
ZeroSilentFailures::Monitor::CallLocation.new(ZSF_DD_TAG_FUNCTION, cl.path, cl.lineno)
end
end
end
end

0 comments on commit 6d947d0

Please sign in to comment.