-
Notifications
You must be signed in to change notification settings - Fork 66
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding additional context for logging |
||
monitor.log_silent_failure_avoided(additional_context) | ||
monitor.track_missing_status_email_sent(form[:form_number]) | ||
send_zsf_notification_to_pega(form) | ||
end | ||
end | ||
end | ||
|
@@ -44,33 +45,56 @@ def perform # rubocop:disable Metrics/MethodLength | |
Rails.logger.error e.backtrace.join("\n") | ||
end | ||
|
||
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 | ||
Comment on lines
-47
to
75
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
# Fires off a notification email to Pega so they know a user has been | ||
# notified of a failed submission. | ||
# | ||
# @param form_data [hash] hash of form details (see `send_failure_email`) | ||
# @param form [IvcChampvaForm] form object in question | ||
def send_zsf_notification_to_pega(form) | ||
form_data = construct_email_payload(form, 'PEGA-TEAM-ZSF') | ||
form_data = form_data.merge({ | ||
email: Settings.vanotify.services.ivc_champva.pega_inbox_address | ||
}) | ||
if IvcChampva::Email.new(form_data).send_email | ||
monitor.track_send_zsf_notification_to_pega(form_data[:form_uuid]) | ||
else | ||
monitor.track_failed_send_zsf_notification_to_pega(form_data[:form_uuid]) | ||
end | ||
end | ||
|
||
def fetch_forms_by_uuid(form_uuid) | ||
@fetch_forms_by_uuid ||= IvcChampvaForm.where(form_uuid:) | ||
end | ||
|
||
## | ||
# retreive a monitor for tracking | ||
# | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,5 +42,23 @@ def track_missing_status_email_sent(form_id) | |
"#{STATS_KEY}.form_missing_status_email_sent", | ||
call_location: caller_locations.first, **additional_context) | ||
end | ||
|
||
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 | ||
Comment on lines
+45
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additional logging in the IVC monitor class |
||
end | ||
end |
There was a problem hiding this comment.
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