Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

95915 Add pega notification email workflow - IVC CHAMPVA forms #19795

Merged
merged 5 commits into from
Dec 11, 2024

Conversation

michaelclement
Copy link
Contributor

@michaelclement michaelclement commented Dec 9, 2024

Summary

This PR adds an email trigger to alert the downstream Pega service when we've fired a ZSF email off to a user. It lets the Pega team keep abreast of any issues to which users have been alerted.

  • Adds logic to send Pega an email
  • Adds new logging metrics to the IvcChampva::Monitor class

Related issue(s)

Testing done

  • New code is covered by unit tests
  • Describe what the old behavior was prior to the change
  • Describe the steps required to verify your changes are working as expected. Exclusively stating 'Specs run' is NOT acceptable as appropriate testing
  • If this work is behind a flipper:
    • Tests need to be written for both the flipper on and flipper off scenarios. Docs.
    • What is the testing plan for rolling out the feature?

Screenshots

NA

What areas of the site does it impact?

IvcChampva module only

Acceptance criteria

  • I fixed|updated|added unit tests and integration tests for each feature (if applicable).
  • No error nor warning in the console.
  • Events are being sent to the appropriate logging solution
  • Documentation has been updated (link to documentation)
  • No sensitive information (i.e. PII/credentials/internal URLs/etc.) is captured in logging, hardcoded, or specs
  • Feature/bug has a monitor built into Datadog (if applicable)
  • If app impacted requires authentication, did you login to a local build and verify all authenticated routes work as expected
  • I added a screenshot of the developed feature

Requested Feedback

NA

@@ -1361,6 +1361,7 @@ vanotify:
ivc_champva:
api_key: fake_secret
failure_email_threshold_days: 7
pega_inbox_address: fake_email_address
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be populated with the current Pega email address via AWS param

@@ -29,9 +29,10 @@ def perform # rubocop:disable Metrics/MethodLength
template_id = "#{form[:form_number]}-FAILURE"
send_failure_email(form, template_id)
if Flipper.enabled?(:champva_enhanced_monitor_logging, @current_user)
additional_context = { form_id: form[:form_number] }
additional_context = { form_id: form[:form_number], form_uuid: form[:form_uuid] }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding additional context for logging

Comment on lines -47 to 75
def fetch_forms_by_uuid(form_uuid)
@fetch_forms_by_uuid ||= IvcChampvaForm.where(form_uuid:)
def construct_email_payload(form, template_id)
{ email: form.email,
first_name: form.first_name,
last_name: form.last_name,
form_number: form.form_number,
file_count: nil,
pega_status: form.pega_status,
created_at: form.created_at.strftime('%B %d, %Y'),
template_id: template_id,
form_uuid: form.form_uuid }
end

# Sends an email to user notifying them of their submission's failure
#
# @param form [IvcChampvaForm] form object in question
# @param template_id [string] key for template to use in `IvcChampva::Email::EMAIL_TEMPLATE_MAP`
def send_failure_email(form, template_id)
form_data =
{
email: form.email,
first_name: form.first_name,
last_name: form.last_name,
form_number: form.form_number,
file_count: nil,
pega_status: form.pega_status,
created_at: form.created_at.strftime('%B %d, %Y'),
template_id: template_id
}
form_data = construct_email_payload(form, template_id)
ActiveRecord::Base.transaction do
if IvcChampva::Email.new(form_data).send_email
fetch_forms_by_uuid(form[:form_uuid]).update_all(email_sent: true) # rubocop:disable Rails/SkipsModelValidations
else
additional_context = { form_id: form[:form_number] }
additional_context = { form_id: form[:form_number], form_uuid: form[:form_uuid] }
monitor.log_silent_failure(additional_context)
raise ActiveRecord::Rollback, 'Pega Status Update/Action Required Email send failure'
end
end
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled the email payload construction out into its own function so it could be cleanly shared with the new send_zsf_notification_to_pega function.

Comment on lines +45 to +62

def track_send_zsf_notification_to_pega(form_uuid)
additional_context = {
form_uuid:
}
track_request('info', "IVC ChampVA Forms - alerted Pega of ZSF email sent for submission #{form_uuid}",
"#{STATS_KEY}.send_zsf_notification_to_pega",
call_location: caller_locations.first, **additional_context)
end

def track_failed_send_zsf_notification_to_pega(form_uuid)
additional_context = {
form_uuid:
}
track_request('warn', "IVC ChampVA Forms - could not alert Pega of ZSF email sent for submission #{form_uuid}",
"#{STATS_KEY}.failed_send_zsf_notification_to_pega",
call_location: caller_locations.first, **additional_context)
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional logging in the IVC monitor class

cloudmagic80
cloudmagic80 previously approved these changes Dec 10, 2024
@michaelclement michaelclement marked this pull request as ready for review December 10, 2024 20:56
@michaelclement michaelclement requested review from a team as code owners December 10, 2024 20:56
@michaelclement michaelclement merged commit e1b5dd3 into master Dec 11, 2024
62 checks passed
@michaelclement michaelclement deleted the add-pega-notification-email-workflow branch December 11, 2024 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants