notify-233: delete notifications from notifications table after they are successfully sent

This commit is contained in:
Kenneth Kehl
2023-04-18 12:42:23 -07:00
parent 81f36182e8
commit 6e3d3f325d
3 changed files with 39 additions and 3 deletions

View File

@@ -7,7 +7,10 @@ from app.clients.email.aws_ses import AwsSesClientThrottlingSendRateException
from app.clients.sms import SmsClientResponseException
from app.config import QueueNames
from app.dao import notifications_dao
from app.dao.notifications_dao import update_notification_status_by_id
from app.dao.notifications_dao import (
insert_notification_history_delete_notifications_by_id,
update_notification_status_by_id,
)
from app.delivery import send_to_providers
from app.exceptions import NotificationTechnicalFailureException
from app.models import NOTIFICATION_TECHNICAL_FAILURE
@@ -37,11 +40,13 @@ def deliver_sms(self, notification_id):
self.retry(queue=QueueNames.RETRY, countdown=0)
else:
self.retry(queue=QueueNames.RETRY)
insert_notification_history_delete_notifications_by_id(notification_id)
except self.MaxRetriesExceededError:
message = "RETRY FAILED: Max retries reached. The task send_sms_to_provider failed for notification {}. " \
"Notification has been updated to technical-failure".format(notification_id)
update_notification_status_by_id(notification_id, NOTIFICATION_TECHNICAL_FAILURE)
raise NotificationTechnicalFailureException(message)
insert_notification_history_delete_notifications_by_id(notification_id)
@notify_celery.task(bind=True, name="deliver_email", max_retries=48, default_retry_delay=300)