mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
Handle errors where the notification isn't found when executing the tasks
- Thows a NoResultFound sqlalchemy exception - Which causes a retry. This means we give it a few goes (5, max 5 hours) for the notification to appear. - Should never happen, only if we get some task overlaps that are unusual that leads to tasks executed in an overlapping nature.
This commit is contained in:
@@ -6,7 +6,7 @@ from app.dao.notifications_dao import update_notification_status_by_id
|
||||
from app.statsd_decorators import statsd
|
||||
|
||||
from app.delivery import send_to_providers
|
||||
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
def retry_iteration_to_delay(retry=0):
|
||||
"""
|
||||
@@ -37,6 +37,8 @@ def retry_iteration_to_delay(retry=0):
|
||||
def deliver_sms(self, notification_id):
|
||||
try:
|
||||
notification = notifications_dao.get_notification_by_id(notification_id)
|
||||
if not notification:
|
||||
raise NoResultFound()
|
||||
send_to_providers.send_sms_to_provider(notification)
|
||||
except Exception as e:
|
||||
try:
|
||||
@@ -58,6 +60,8 @@ def deliver_sms(self, notification_id):
|
||||
def deliver_email(self, notification_id):
|
||||
try:
|
||||
notification = notifications_dao.get_notification_by_id(notification_id)
|
||||
if not notification:
|
||||
raise NoResultFound()
|
||||
send_to_providers.send_email_to_provider(notification)
|
||||
except Exception as e:
|
||||
try:
|
||||
@@ -78,7 +82,10 @@ def deliver_email(self, notification_id):
|
||||
@statsd(namespace="tasks")
|
||||
def send_sms_to_provider(self, service_id, notification_id):
|
||||
try:
|
||||
send_to_providers.send_sms_to_provider(notification_id)
|
||||
notification = notifications_dao.get_notification_by_id(notification_id)
|
||||
if not notification:
|
||||
raise NoResultFound()
|
||||
send_to_providers.send_sms_to_provider(notification)
|
||||
except Exception as e:
|
||||
try:
|
||||
current_app.logger.error(
|
||||
@@ -98,7 +105,10 @@ def send_sms_to_provider(self, service_id, notification_id):
|
||||
@statsd(namespace="tasks")
|
||||
def send_email_to_provider(self, service_id, notification_id):
|
||||
try:
|
||||
send_to_providers.send_email_response(notification_id)
|
||||
notification = notifications_dao.get_notification_by_id(notification_id)
|
||||
if not notification:
|
||||
raise NoResultFound()
|
||||
send_to_providers.send_email_to_provider(notification)
|
||||
except Exception as e:
|
||||
try:
|
||||
current_app.logger.error(
|
||||
|
||||
Reference in New Issue
Block a user