mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
Merge branch 'master' into caching-with-redis
Conflicts: app/celery/tasks.py tests/app/celery/test_tasks.py
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
from datetime import datetime
|
||||
|
||||
from flask import current_app
|
||||
from notifications_utils.renderers import PassThrough
|
||||
from notifications_utils.template import Template
|
||||
|
||||
from app import DATETIME_FORMAT
|
||||
from app.celery import provider_tasks
|
||||
from app.dao.notifications_dao import dao_create_notification, dao_delete_notifications_and_history_by_id
|
||||
from app.models import SMS_TYPE, Notification, KEY_TYPE_TEST, EMAIL_TYPE
|
||||
@@ -40,15 +43,23 @@ def persist_notification(template_id,
|
||||
personalisation,
|
||||
notification_type,
|
||||
api_key_id,
|
||||
key_type):
|
||||
notification = Notification.from_v2_api_request(template_id=template_id,
|
||||
template_version=template_version,
|
||||
recipient=recipient,
|
||||
service_id=service_id,
|
||||
personalisation=personalisation,
|
||||
notification_type=notification_type,
|
||||
api_key_id=api_key_id,
|
||||
key_type=key_type)
|
||||
key_type,
|
||||
created_at=None,
|
||||
job_id=None,
|
||||
job_row_number=None):
|
||||
notification = Notification(
|
||||
template_id=template_id,
|
||||
template_version=template_version,
|
||||
to=recipient,
|
||||
service_id=service_id,
|
||||
personalisation=personalisation,
|
||||
notification_type=notification_type,
|
||||
api_key_id=api_key_id,
|
||||
key_type=key_type,
|
||||
created_at=created_at if created_at else datetime.utcnow().strftime(DATETIME_FORMAT),
|
||||
job_id=job_id,
|
||||
job_row_number=job_row_number
|
||||
)
|
||||
dao_create_notification(notification)
|
||||
return notification
|
||||
|
||||
@@ -69,7 +80,7 @@ def send_notification_to_queue(notification, research_mode):
|
||||
except Exception as e:
|
||||
current_app.logger.exception("Failed to send to SQS exception")
|
||||
dao_delete_notifications_and_history_by_id(notification.id)
|
||||
raise
|
||||
raise e
|
||||
|
||||
current_app.logger.info(
|
||||
"{} {} created at {}".format(notification.notification_type, notification.id, notification.created_at)
|
||||
|
||||
@@ -242,7 +242,10 @@ def send_notification(notification_type):
|
||||
notification_type=notification_type,
|
||||
api_key_id=api_user.id,
|
||||
key_type=api_user.key_type)
|
||||
send_notification_to_queue(saved_notification, service.research_mode)
|
||||
try:
|
||||
send_notification_to_queue(saved_notification, service.research_mode)
|
||||
except Exception as e:
|
||||
return jsonify(result='error', message="Internal server error"), 500
|
||||
|
||||
notification_id = create_uuid() if saved_notification is None else saved_notification.id
|
||||
notification.update({"template_version": template.version})
|
||||
|
||||
Reference in New Issue
Block a user