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

#2173 - send va profile sms delivery status #2153

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c0374bf
#2173 - Send VA Profile SMS Delivery Status
MackHalliday Dec 2, 2024
5d98ac5
Merge branch 'main' into 2173-send-va-profile-sms-delivery-status
MackHalliday Dec 2, 2024
8bcb684
Merge github.com:department-of-veterans-affairs/notification-api into…
MackHalliday Dec 2, 2024
43cfdbe
Squash #2137 - testing pass for sms and email for new testing module
MackHalliday Dec 2, 2024
b6ef909
Squash #2137 - Update feature flag and add logic to send status if no…
MackHalliday Dec 2, 2024
0f12381
Squash #2137 - Reuse feature flag for enabling sending sms to vaprofile
MackHalliday Dec 2, 2024
1efff50
Squash #2137 - Reuse feature flag for enabling sending sms to vaprofi…
MackHalliday Dec 2, 2024
ee59670
Merge branch '2173-send-va-profile-sms-delivery-status' of github.com…
MackHalliday Dec 2, 2024
8e6e257
Squash #2137 - Move send notification status call to VAPROFILE to own…
MackHalliday Dec 2, 2024
ac34a12
Squash #2137 - Add back delay
MackHalliday Dec 3, 2024
946818c
Squash #2137 - Update old failing ses test after refactor, add note a…
MackHalliday Dec 3, 2024
f876f11
Squash #2137 - Add TODOs regarding failing test related to Celery async
MackHalliday Dec 3, 2024
cd84a59
Squash #2137 - Fix failing test test_ses_callback_should_set_status_t…
MackHalliday Dec 3, 2024
f0f246b
Squash #2137 - Fix failing test test_ses_callback_should_set_status_t…
MackHalliday Dec 3, 2024
ae4adac
Squash #2137 - Correct COMP_AND_PEN_MESSAGES_ENABLED accidently switc…
MackHalliday Dec 3, 2024
1600c77
Squash #2137 - Complete updates to sses failing test
MackHalliday Dec 4, 2024
5beab0b
Squash #2137 - Update import sort according to pep 8
MackHalliday Dec 4, 2024
28de317
Squash #2137 - Update testing config to run as always eager so featur…
MackHalliday Dec 4, 2024
af7d54e
Squash #2137 - send va profile notification statues test passing - re…
MackHalliday Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ fileignoreconfig:
- filename: app/va/va_profile/va_profile_client.py
checksum: fe634f26f7dc3874f4afcfd1ba3f03bae380b53befe973a752c7347097a88701
- filename: cd/application-deployment/dev/dev.env
checksum: 2ecdf2787dd15a7971471b5b6b799adf478a8021552e690de76b682f5e7344a3
checksum: d0897f1124e6725347d18a9ba8de56baf848151ecad688db189e0ec2d6282bcb
- filename: cd/application-deployment/dev/vaec-api-task-definition.json
checksum: f328ff821339b802eb1d82559e624d5b719857c813d427da5aaa39b240331ddd
- filename: cd/application-deployment/perf/perf.env
checksum: 06912f9617483c19b076d92f0036c125f0a2f80e10a1665e5ddc5ce31a354a5c
checksum: d8f93f6bf746751e364d4cb81f26e656bd7ed0f146d98c03fd704d716acc5805
- filename: cd/application-deployment/prod/prod.env
checksum: 64f46f118e9f652c663bc53225ddf39f1ef85040ea3e24fceb71ea752984d46c
checksum: 949dc3234b36d9fc8706a927b5c342372aa1ac5d6ba8f9458f7482e0ee31a180
- filename: cd/application-deployment/staging/staging.env
checksum: ce893a6a8405ad66d7b8efa8e1b1991c9ae6bebb245d500e93d148e1142b714d
checksum: 21e3b7b3249dd80251670bee519a6bbc3b5fff0261177b83f6f1a801f5951975
- filename: ci/.local.env
checksum: 2c4024d4e94ffa39ff73e6039d65f0b1d19557067ddf6d97ef14aea86cfb58ad
- filename: ci/docker-compose-test.yml
Expand Down
2 changes: 2 additions & 0 deletions app/celery/process_delivery_status_result_tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
from typing import Tuple

from app.celery.process_ses_receipts_tasks import check_and_queue_va_profile_email_status_callback
from celery import Task
from flask import current_app
from notifications_utils.statsd_decorators import statsd
Expand Down Expand Up @@ -259,6 +260,7 @@ def sms_status_update(
# Only send if there was an update
if last_updated_at != notification.updated_at:
check_and_queue_callback_task(notification, sms_status.payload)
check_and_queue_va_profile_email_status_callback(notification)
statsd_client.incr(f'clients.sms.{sms_status.provider}.status_update.success')
except Exception:
current_app.logger.exception('Failed to check_and_queue_callback_task for notification: %s', notification.id)
Expand Down
69 changes: 2 additions & 67 deletions app/celery/process_ses_receipts_tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime, timedelta

from app.celery.send_va_profile_notification_status import check_and_queue_va_profile_email_status_callback
import iso8601
from app.celery.common import log_notification_total_time
from celery.exceptions import Retry
Expand All @@ -15,12 +16,10 @@
import enum
import requests

from app import notify_celery, statsd_client, va_profile_client
from app.celery.exceptions import AutoRetryException
from app import notify_celery, statsd_client
from app.celery.service_callback_tasks import publish_complaint
from app.config import QueueNames
from app.constants import (
DATETIME_FORMAT,
EMAIL_TYPE,
HTTP_TIMEOUT,
KEY_TYPE_NORMAL,
Expand All @@ -32,8 +31,6 @@
)
from app.clients.email.aws_ses import get_aws_responses
from app.dao import notifications_dao, services_dao, templates_dao
from app.feature_flags import FeatureFlag, is_feature_enabled
from app.models import Notification
from json import decoder
from app.notifications import process_notifications
from app.notifications.notifications_ses_callback import (
Expand Down Expand Up @@ -358,65 +355,3 @@ def process_ses_smtp_results(
current_app.logger.exception(e)
current_app.logger.error('Error processing SES SMTP results: %s', type(e))
self.retry(queue=QueueNames.RETRY)


def check_and_queue_va_profile_email_status_callback(notification: Notification) -> None:
"""
This checks the feature flag is enabled. If it is, queues the celery task and collects data from the notification.
Otherwise, it only logs a message.

:param notification: the email notification to collect data from
"""

current_app.logger.debug(
'Sending email status to VA Profile, checking feature flag... | notification %s', notification.id
)

if is_feature_enabled(FeatureFlag.VA_PROFILE_EMAIL_STATUS_ENABLED):
current_app.logger.debug(
'Sending email status to VA Profile, collecting data for notification %s', notification.id
)
notification_data = {
'id': str(notification.id), # this is the notification id
'reference': notification.client_reference,
'to': notification.to, # this is the recipient's contact info (email)
'status': notification.status, # this will specify the delivery status of the notification
'status_reason': notification.status_reason, # populated if there's additional context on the delivery status
'created_at': notification.created_at.strftime(DATETIME_FORMAT), # noqa: F821
'completed_at': notification.updated_at.strftime(DATETIME_FORMAT) if notification.updated_at else None,
'sent_at': notification.sent_at.strftime(DATETIME_FORMAT) if notification.sent_at else None,
'notification_type': notification.notification_type, # this is the channel/type of notification (email)
'provider': notification.sent_by, # email provider
}

# data passed to tasks must be JSON serializable
send_email_status_to_va_profile.delay(notification_data)
else:
current_app.logger.debug(
'Email status not sent to VA Profile, feature flag disabled | notification %s', notification.id
)


@notify_celery.task(
throws=(AutoRetryException,),
autoretry_for=(AutoRetryException,),
max_retries=60,
retry_backoff=True,
retry_backoff_max=3600,
)
def send_email_status_to_va_profile(notification_data: dict) -> None:
"""
This function calls the VAProfileClient method to send the information to VA Profile.

:param notification_data: the email notification data to send
"""

try:
va_profile_client.send_va_profile_email_status(notification_data)
except requests.Timeout:
# logging in send_va_profile_email_status
raise AutoRetryException
except requests.RequestException:
# logging in send_va_profile_email_status
# In this case the error is being handled by not retrying this celery task
pass
70 changes: 70 additions & 0 deletions app/celery/send_va_profile_notification_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import requests

from flask import current_app

from app import notify_celery, va_profile_client
from app.celery.exceptions import AutoRetryException
from app.constants import DATETIME_FORMAT, EMAIL_TYPE
from app.feature_flags import FeatureFlag, is_feature_enabled
from app.models import Notification


def check_and_queue_va_profile_email_status_callback(notification: Notification) -> None:
"""
This checks the feature flag is enabled. If it is, queues the celery task and collects data from the notification.
Otherwise, it only logs a message.

:param notification: the email notification to collect data from
"""
current_app.logger.debug(
'Sending email status to VA Profile, checking feature flag... | notification %s', notification.id
)

if is_feature_enabled(FeatureFlag.VA_PROFILE_SMS_STATUS_ENABLED) or notification.notification_type == EMAIL_TYPE:
current_app.logger.debug(
'Sending email status to VA Profile, collecting data for notification %s', notification.id
)
notification_data = {
'id': str(notification.id), # this is the notification id
'reference': notification.client_reference,
'to': notification.to, # this is the recipient's contact info (email)
'status': notification.status, # this will specify the delivery status of the notification
'status_reason': notification.status_reason, # populated if there's additional context on the delivery status
'created_at': notification.created_at.strftime(DATETIME_FORMAT), # noqa: F821
'completed_at': notification.updated_at.strftime(DATETIME_FORMAT) if notification.updated_at else None,
'sent_at': notification.sent_at.strftime(DATETIME_FORMAT) if notification.sent_at else None,
'notification_type': notification.notification_type, # this is the channel/type of notification (email)
'provider': notification.sent_by, # email provider
}

# data passed to tasks must be JSON serializable
send_email_status_to_va_profile.delay(notification_data)
else:
current_app.logger.debug(
'SMS status not sent to VA Profile, feature flag disabled | notification %s', notification.id
)


@notify_celery.task(
throws=(AutoRetryException,),
autoretry_for=(AutoRetryException,),
max_retries=60,
retry_backoff=True,
retry_backoff_max=3600,
)
def send_email_status_to_va_profile(notification_data: dict) -> None:
"""
This function calls the VAProfileClient method to send the information to VA Profile.

:param notification_data: the email notification data to send
"""

try:
va_profile_client.send_va_profile_email_status(notification_data)
except requests.Timeout:
# logging in send_va_profile_email_status
raise AutoRetryException
except requests.RequestException:
# logging in send_va_profile_email_status
# In this case the error is being handled by not retrying this celery task
pass
2 changes: 1 addition & 1 deletion app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class Test(Development):
'read-db': os.getenv('SQLALCHEMY_DATABASE_URI_READ', 'postgresql://postgres@localhost/notification_api')
}

CELERY_SETTINGS = {'broker_url': 'you-forgot-to-mock-celery-in-your-tests://'}
CELERY_SETTINGS = {'task_always_eager': True, 'broker_url': 'memory://'}

ANTIVIRUS_ENABLED = True

Expand Down
2 changes: 1 addition & 1 deletion app/feature_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FeatureFlag(Enum):
VA_SSO_ENABLED = 'VA_SSO_ENABLED'
V3_ENABLED = 'V3_ENABLED'
COMP_AND_PEN_MESSAGES_ENABLED = 'COMP_AND_PEN_MESSAGES_ENABLED'
VA_PROFILE_EMAIL_STATUS_ENABLED = 'VA_PROFILE_EMAIL_STATUS_ENABLED'
VA_PROFILE_SMS_STATUS_ENABLED = 'VA_PROFILE_SMS_STATUS_ENABLED'


def accept_recipient_identifiers_enabled():
Expand Down
2 changes: 0 additions & 2 deletions app/va/va_profile/va_profile_client.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from __future__ import annotations

from dataclasses import dataclass
from enum import Enum
from http.client import responses
from logging import Logger
from typing import TYPE_CHECKING, Optional


import iso8601
import requests

Expand Down
2 changes: 1 addition & 1 deletion cd/application-deployment/dev/dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ VANOTIFY_SSL_CERT_PATH=/app/certs/vanotify_ssl_cert.pem
VANOTIFY_SSL_KEY_PATH=/app/certs/vanotify_ssl_key.pem
VA_FLAGSHIP_APP_SID=A20623E2321D4053A6C34C9307C6C221
VA_ONSITE_URL=https://staging-api.va.gov
VA_PROFILE_EMAIL_STATUS_ENABLED=True
VA_PROFILE_SMS_STATUS_ENABLED=True
VA_PROFILE_URL=https://int.vaprofile.va.gov
VA_SSO_ACCESS_TOKEN_URL=https://int.fed.eauth.va.gov/oauthi/sps/oauth/oauth20/token
VA_SSO_AUTHORIZE_URL=https://int.fed.eauth.va.gov/oauthi/sps/oauth/oauth20/authorize
Expand Down
2 changes: 1 addition & 1 deletion cd/application-deployment/perf/perf.env
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ VANOTIFY_SSL_CERT_PATH=/app/certs/vanotify_ssl_cert.pem
VANOTIFY_SSL_KEY_PATH=/app/certs/vanotify_ssl_key.pem
VA_FLAGSHIP_APP_SID=A20623E2321D4053A6C34C9307C6C221
VA_ONSITE_URL=https://staging-api.va.gov
VA_PROFILE_EMAIL_STATUS_ENABLED=True
VA_PROFILE_SMS_STATUS_ENABLED=True
VA_PROFILE_URL=https://qa.vaprofile.va.gov
VA_SSO_ACCESS_TOKEN_URL=https://preprod.fed.eauth.va.gov/oauthi/sps/oauth/oauth20/token
VA_SSO_AUTHORIZE_URL=https://preprod.fed.eauth.va.gov/oauthi/sps/oauth/oauth20/authorize
Expand Down
2 changes: 1 addition & 1 deletion cd/application-deployment/prod/prod.env
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ VANOTIFY_SSL_CERT_PATH=/app/certs/vanotify_ssl_cert.pem
VANOTIFY_SSL_KEY_PATH=/app/certs/vanotify_ssl_key.pem
VA_FLAGSHIP_APP_SID=D288162B716A4F55B9F5CF9AA9DDEA5E
VA_ONSITE_URL=https://api.va.gov
VA_PROFILE_EMAIL_STATUS_ENABLED=True
VA_PROFILE_SMS_STATUS_ENABLED=False
VA_PROFILE_URL=https://www.vaprofile.va.gov
VA_SSO_ACCESS_TOKEN_URL=https://fed.eauth.va.gov/oauthi/sps/oauth/oauth20/token
VA_SSO_AUTHORIZE_URL=https://fed.eauth.va.gov/oauthi/sps/oauth/oauth20/authorize
Expand Down
2 changes: 1 addition & 1 deletion cd/application-deployment/staging/staging.env
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ VANOTIFY_SSL_CERT_PATH=/app/certs/vanotify_ssl_cert.pem
VANOTIFY_SSL_KEY_PATH=/app/certs/vanotify_ssl_key.pem
VA_FLAGSHIP_APP_SID=A20623E2321D4053A6C34C9307C6C221
VA_ONSITE_URL=https://staging-api.va.gov
VA_PROFILE_EMAIL_STATUS_ENABLED=True
VA_PROFILE_SMS_STATUS_ENABLED=True
VA_PROFILE_URL=https://qa.vaprofile.va.gov
VA_SSO_ACCESS_TOKEN_URL=https://sqa.fed.eauth.va.gov/oauthi/sps/oauth/oauth20/token
VA_SSO_AUTHORIZE_URL=https://sqa.fed.eauth.va.gov/oauthi/sps/oauth/oauth20/authorize
Expand Down
Loading
Loading