mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Reinstating the 2 task model for API submitted notifications.
This is being done for the PaaS migration to allow us to keep traffic coming in whilst we migrate the database. uses the same tasks as the CSV uploaded notifications. Simple changes to not persist the notification, and call into a different task.
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
from flask import request, jsonify, current_app
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from app import api_user
|
||||
from app import api_user, encryption, create_uuid
|
||||
from app.celery import tasks
|
||||
from app.dao import services_dao, templates_dao
|
||||
from app.models import SMS_TYPE, EMAIL_TYPE, PRIORITY
|
||||
from app.models import SMS_TYPE, EMAIL_TYPE, PRIORITY, KEY_TYPE_TEST
|
||||
from app.notifications.process_notifications import (create_content_for_notification,
|
||||
persist_notification,
|
||||
send_notification_to_queue,
|
||||
@@ -39,19 +40,44 @@ def post_notification(notification_type):
|
||||
|
||||
# Do not persist or send notification to the queue if it is a simulated recipient
|
||||
simulated = simulated_recipient(send_to, notification_type)
|
||||
notification = persist_notification(template_id=template.id,
|
||||
template_version=template.version,
|
||||
recipient=send_to,
|
||||
service=service,
|
||||
personalisation=form.get('personalisation', None),
|
||||
notification_type=notification_type,
|
||||
api_key_id=api_user.id,
|
||||
key_type=api_user.key_type,
|
||||
reference=form.get('reference', None),
|
||||
simulated=simulated)
|
||||
notification = persist_notification(
|
||||
notification_id=create_uuid(),
|
||||
template_id=template.id,
|
||||
template_version=template.version,
|
||||
recipient=send_to,
|
||||
service=service,
|
||||
personalisation=form.get('personalisation', {}),
|
||||
notification_type=notification_type,
|
||||
api_key_id=api_user.id,
|
||||
key_type=api_user.key_type,
|
||||
reference=form.get('reference', None),
|
||||
simulated=simulated,
|
||||
persist=False)
|
||||
|
||||
notification_data = {
|
||||
'template': str(template.id),
|
||||
'template_version': template.version,
|
||||
'to': send_to
|
||||
}
|
||||
if notification.personalisation:
|
||||
notification_data.update({
|
||||
'personalisation': dict(notification.personalisation)
|
||||
})
|
||||
|
||||
encrypted = encryption.encrypt(notification_data)
|
||||
|
||||
if not simulated:
|
||||
queue_name = 'notify' if template.process_type == PRIORITY else None
|
||||
send_notification_to_queue(notification=notification, research_mode=service.research_mode, queue=queue_name)
|
||||
tasks.send_notification_to_persist_queue(
|
||||
notification.id,
|
||||
service,
|
||||
template.template_type,
|
||||
encrypted,
|
||||
template.process_type == PRIORITY,
|
||||
service.research_mode or api_user.key_type == KEY_TYPE_TEST
|
||||
)
|
||||
# not doing this during paas migration
|
||||
# queue_name = 'notify' if template.process_type == PRIORITY else None
|
||||
# send_notification_to_queue(notification=notification, research_mode=service.research_mode, queue=queue_name)
|
||||
else:
|
||||
current_app.logger.info("POST simulated notification for id: {}".format(notification.id))
|
||||
if notification_type == SMS_TYPE:
|
||||
|
||||
Reference in New Issue
Block a user