Skip to content

Commit

Permalink
Add notification email dispatch logging (#18726)
Browse files Browse the repository at this point in the history
The Form0781DocumentUploadFailureEmail and Form4142DocumentUploadFailureEmail jobs are used to send VA Notify emails to Veterans when those respective forms fail to upload to EVSS so they can do a manual workaround

These jobs were missing a logging statement for dispatching the email, which we want to use in DataDog to monitor the frequency and success rate of sending these emails
  • Loading branch information
NB28VT authored Oct 3, 2024
1 parent 1aab2b3 commit a2bc64b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def perform(form526_submission_id)
}
)

StatsD.increment("#{STATSD_METRIC_PREFIX}.success")
log_mailer_dispatch(form526_submission_id)
end
rescue => e
retryable_error_handler(e)
Expand All @@ -95,6 +95,18 @@ def retryable_error_handler(error)
raise error
end

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

StatsD.increment("#{STATSD_METRIC_PREFIX}.success")
end

def mailer_template_id
Settings.vanotify.services
.benefits_disability.template_id.form0781_upload_failure_notification_template_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def perform(form526_submission_id)
}
)

StatsD.increment("#{STATSD_METRIC_PREFIX}.success")
log_mailer_dispatch(form526_submission_id)
end
rescue => e
retryable_error_handler(e)
Expand All @@ -95,6 +95,18 @@ def retryable_error_handler(error)
raise error
end

def log_mailer_dispatch(form526_submission_id)
Rails.logger.info(
'Form4142DocumentUploadFailureEmail notification dispatched',
{
form526_submission_id:,
timestamp: Time.now.utc
}
)

StatsD.increment("#{STATSD_METRIC_PREFIX}.success")
end

def mailer_template_id
Settings.vanotify.services
.benefits_disability.template_id.form4142_upload_failure_notification_template_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
end

describe 'logging' do
it 'increments a Statsd metric' do
before do
allow(notification_client).to receive(:send_email)
end

it 'increments a Statsd metric' do
expect do
subject.perform_async(form526_submission.id)
subject.drain
Expand All @@ -49,9 +51,25 @@
)
end

it 'creates a Form526JobStatus' do
allow(notification_client).to receive(:send_email)
it 'logs to the Rails logger' do
allow(Rails.logger).to receive(:info)
exhaustion_time = Time.new(1985, 10, 26).utc

Timecop.freeze(exhaustion_time) do
subject.perform_async(form526_submission.id)
subject.drain

expect(Rails.logger).to have_received(:info).with(
'Form0781DocumentUploadFailureEmail notification dispatched',
{
form526_submission_id: form526_submission.id,
timestamp: exhaustion_time
}
)
end
end

it 'creates a Form526JobStatus' do
expect do
subject.perform_async(form526_submission.id)
subject.drain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
end

describe 'logging' do
it 'increments a Statsd metric' do
before do
allow(notification_client).to receive(:send_email)
end

it 'increments a Statsd metric' do
expect do
subject.perform_async(form526_submission.id)
subject.drain
Expand All @@ -49,9 +51,25 @@
)
end

it 'creates a Form526JobStatus' do
allow(notification_client).to receive(:send_email)
it 'logs to the Rails logger' do
allow(Rails.logger).to receive(:info)
exhaustion_time = Time.new(1985, 10, 26).utc

Timecop.freeze(exhaustion_time) do
subject.perform_async(form526_submission.id)
subject.drain

expect(Rails.logger).to have_received(:info).with(
'Form4142DocumentUploadFailureEmail notification dispatched',
{
form526_submission_id: form526_submission.id,
timestamp: exhaustion_time
}
)
end
end

it 'creates a Form526JobStatus' do
expect do
subject.perform_async(form526_submission.id)
subject.drain
Expand Down

0 comments on commit a2bc64b

Please sign in to comment.