mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-13 08:42:21 -05:00
Don't send the SMS if we have failed to save in the database
This commit is contained in:
@@ -4,6 +4,7 @@ from app.dao.templates_dao import get_model_templates
|
||||
from app.dao.notifications_dao import save_notification
|
||||
from app.models import Notification
|
||||
from flask import current_app
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
|
||||
@notify_celery.task(name="send-sms")
|
||||
@@ -11,20 +12,21 @@ def send_sms(service_id, notification_id, encrypted_notification):
|
||||
notification = encryption.decrypt(encrypted_notification)
|
||||
template = get_model_templates(notification['template'])
|
||||
|
||||
status = 'sent'
|
||||
|
||||
try:
|
||||
twilio_client.send_sms(notification['to'], template.content)
|
||||
except TwilioClientException as e:
|
||||
current_app.logger.info(e)
|
||||
status = 'failed'
|
||||
notification_db_object = Notification(
|
||||
id=notification_id,
|
||||
template_id=notification['template'],
|
||||
to=notification['to'],
|
||||
service_id=service_id,
|
||||
status='sent'
|
||||
)
|
||||
save_notification(notification_db_object)
|
||||
|
||||
notification_db_object = Notification(
|
||||
id=notification_id,
|
||||
template_id=notification['template'],
|
||||
to=notification['to'],
|
||||
service_id=service_id,
|
||||
status=status
|
||||
)
|
||||
try:
|
||||
twilio_client.send_sms(notification['to'], template.content)
|
||||
except TwilioClientException as e:
|
||||
current_app.logger.debug(e)
|
||||
save_notification(notification_db_object, {"status": "failed"})
|
||||
|
||||
save_notification(notification_db_object)
|
||||
except SQLAlchemyError as e:
|
||||
current_app.logger.debug(e)
|
||||
|
||||
Reference in New Issue
Block a user