mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 21:48:49 -04:00
notify-152 sms delivery receipts
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
from datetime import datetime, timedelta
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from flask import current_app
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from app import notify_celery
|
||||
from app.clients.cloudwatch.aws_cloudwatch import AwsCloudwatchClient
|
||||
from app.clients.email import EmailClientNonRetryableException
|
||||
from app.clients.email.aws_ses import AwsSesClientThrottlingSendRateException
|
||||
from app.clients.sms import SmsClientResponseException
|
||||
@@ -10,7 +14,24 @@ from app.dao import notifications_dao
|
||||
from app.dao.notifications_dao import update_notification_status_by_id
|
||||
from app.delivery import send_to_providers
|
||||
from app.exceptions import NotificationTechnicalFailureException
|
||||
from app.models import NOTIFICATION_TECHNICAL_FAILURE
|
||||
from app.models import (
|
||||
NOTIFICATION_FAILED,
|
||||
NOTIFICATION_SENT,
|
||||
NOTIFICATION_TECHNICAL_FAILURE,
|
||||
)
|
||||
|
||||
|
||||
@notify_celery.task(bind=True, name="check_sms_delivery_receipt", max_retries=3, default_retry_delay=300)
|
||||
def check_sms_delivery_receipt(self, message_id, notification_id):
|
||||
current_app.logger.warning(f"CHECKING DELIVERY RECEIPT for {message_id} {notification_id}")
|
||||
cloudwatch_client = AwsCloudwatchClient()
|
||||
cloudwatch_client.init_app(current_app)
|
||||
status, provider_response = cloudwatch_client.check_sms(message_id, notification_id)
|
||||
if status == 'success':
|
||||
status = NOTIFICATION_SENT
|
||||
else:
|
||||
status = NOTIFICATION_FAILED
|
||||
update_notification_status_by_id(notification_id, status, provider_response=provider_response)
|
||||
|
||||
|
||||
@notify_celery.task(bind=True, name="deliver_sms", max_retries=48, default_retry_delay=300)
|
||||
@@ -20,7 +41,15 @@ def deliver_sms(self, notification_id):
|
||||
notification = notifications_dao.get_notification_by_id(notification_id)
|
||||
if not notification:
|
||||
raise NoResultFound()
|
||||
send_to_providers.send_sms_to_provider(notification)
|
||||
message_id = send_to_providers.send_sms_to_provider(notification)
|
||||
# We have to put it in the default US/Eastern timezone. From zones west of there, the delay
|
||||
# will be ignored and it will fire immediately (although this probably only affects developer testing)
|
||||
my_eta = datetime.now(ZoneInfo('US/Eastern')) + timedelta(seconds=300)
|
||||
check_sms_delivery_receipt.apply_async(
|
||||
[message_id, notification_id],
|
||||
eta=my_eta,
|
||||
queue=QueueNames.CHECK_SMS
|
||||
)
|
||||
except Exception as e:
|
||||
if isinstance(e, SmsClientResponseException):
|
||||
current_app.logger.warning(
|
||||
|
||||
Reference in New Issue
Block a user