Skip to content

Commit

Permalink
update failure_notification_email_job.rb and test to include lighthouse
Browse files Browse the repository at this point in the history
  • Loading branch information
pmclaren19 committed Dec 30, 2024
1 parent b24e2ae commit 2854671
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,69 @@
require 'sidekiq'
require 'lighthouse/benefits_documents/constants'

module BenefitsDocuments
class FailureNotificationEmailJob
include Sidekiq::Job
include SentryLogging
module Lighthouse
module BenefitsDocuments
class FailureNotificationEmailJob
include Sidekiq::Job
include SentryLogging

sidekiq_options retry: false, unique_for: 30.minutes
NOTIFY_SETTINGS = Settings.vanotify.services.benefits_management_tools
MAILER_TEMPLATE_ID = NOTIFY_SETTINGS.template_id.evidence_submission_failure_email
# TODO: need to add statsd logic
# STATSD_KEY_PREFIX = ''
sidekiq_options retry: false, unique_for: 30.minutes
NOTIFY_SETTINGS = Settings.vanotify.services.benefits_management_tools
MAILER_TEMPLATE_ID = NOTIFY_SETTINGS.template_id.evidence_submission_failure_email
# TODO: need to add statsd logic
# STATSD_KEY_PREFIX = ''

def perform
return unless should_perform?
def perform
return unless should_perform?

send_failed_evidence_submissions
send_failed_evidence_submissions

nil
end

def should_perform?
failed_uploads.present?
end
nil
end

# Fetches FAILED evidence submission records for BenefitsDocuments that dont have a va_notify_date
def failed_uploads
@failed_uploads ||= EvidenceSubmission.va_notify_email_not_queued
end
def should_perform?
failed_uploads.present?
end

def notify_client
VaNotify::Service.new(NOTIFY_SETTINGS.api_key)
end
# Fetches FAILED evidence submission records for BenefitsDocuments that dont have a va_notify_date
def failed_uploads
@failed_uploads ||= EvidenceSubmission.va_notify_email_not_queued
end

def send_failed_evidence_submissions
failed_uploads.each do |upload|
personalisation = JSON.parse(upload.template_metadata_ciphertext)['personalisation']
response = notify_client.send_email(
recipient_identifier: { id_value: upload.user_account.icn, id_type: 'ICN' },
template_id: MAILER_TEMPLATE_ID,
personalisation:
)
record_email_send_success(upload, response)
rescue => e
record_email_send_failure(upload, e)
def notify_client
VaNotify::Service.new(NOTIFY_SETTINGS.api_key)
end

nil
end
def send_failed_evidence_submissions
failed_uploads.each do |upload|
personalisation = JSON.parse(upload.template_metadata_ciphertext)['personalisation']
response = notify_client.send_email(
recipient_identifier: { id_value: upload.user_account.icn, id_type: 'ICN' },
template_id: MAILER_TEMPLATE_ID,
personalisation:
)
record_email_send_success(upload, response)
rescue => e
record_email_send_failure(upload, e)
end

def record_email_send_success(upload, response)
upload.update(va_notify_id: response.id, va_notify_date: DateTime.now)
message = "#{upload.job_class} va notify failure email queued"
::Rails.logger.info(message)
StatsD.increment('silent_failure_avoided_no_confirmation',
tags: ['service:claim-status', "function: #{message}"])
end
nil
end

def record_email_send_failure(upload, error)
error_message = "#{upload.job_class} va notify failure email errored"
::Rails.logger.error(error_message, { message: error.message })
StatsD.increment('silent_failure', tags: ['service:claim-status', "function: #{error_message}"])
log_exception_to_sentry(error)
def record_email_send_success(upload, response)
upload.update(va_notify_id: response.id, va_notify_date: DateTime.now)
message = "#{upload.job_class} va notify failure email queued"
::Rails.logger.info(message)
StatsD.increment('silent_failure_avoided_no_confirmation',
tags: ['service:claim-status', "function: #{message}"])

Check failure on line 60 in app/sidekiq/lighthouse/benefits_documents/failure_notification_email_job.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
end

def record_email_send_failure(upload, error)
error_message = "#{upload.job_class} va notify failure email errored"
::Rails.logger.error(error_message, { message: error.message })
StatsD.increment('silent_failure', tags: ['service:claim-status', "function: #{error_message}"])
log_exception_to_sentry(error)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# frozen_string_literal: true

require 'rails_helper'

require 'lighthouse/benefits_documents/failure_notification_email_job'
require 'va_notify/service'

RSpec.describe BenefitsDocuments::FailureNotificationEmailJob, type: :job do
RSpec.describe Lighthouse::BenefitsDocuments::FailureNotificationEmailJob, type: :job do
subject { described_class }

let(:notify_client_stub) { instance_double(VaNotify::Service) }
Expand Down

0 comments on commit 2854671

Please sign in to comment.