mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Revert "Reinstating the 2 task model for API submitted notifications."
This reverts commit 1c154c4113.
This commit is contained in:
@@ -123,39 +123,6 @@ def process_row(row_number, recipient, personalisation, template, job, service):
|
||||
)
|
||||
|
||||
|
||||
def send_notification_to_persist_queue(
|
||||
notification_id, service, template_type, encrypted, priority=False, research_mode=False
|
||||
):
|
||||
queues = {
|
||||
SMS_TYPE: 'db-sms',
|
||||
EMAIL_TYPE: 'db-email'
|
||||
}
|
||||
|
||||
send_fns = {
|
||||
SMS_TYPE: send_sms,
|
||||
EMAIL_TYPE: send_email
|
||||
}
|
||||
|
||||
send_fn = send_fns[template_type]
|
||||
|
||||
if research_mode:
|
||||
queue_name = "research-mode"
|
||||
elif priority:
|
||||
queue_name = "notify"
|
||||
else:
|
||||
queue_name = queues[template_type]
|
||||
|
||||
send_fn.apply_async(
|
||||
(
|
||||
str(service.id),
|
||||
notification_id,
|
||||
encrypted,
|
||||
datetime.utcnow().strftime(DATETIME_FORMAT)
|
||||
),
|
||||
queue=queue_name
|
||||
)
|
||||
|
||||
|
||||
def __sending_limits_for_job_exceeded(service, job, job_id):
|
||||
total_sent = fetch_todays_total_message_count(service.id)
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ from flask import current_app
|
||||
from app import redis_store
|
||||
from app.celery import provider_tasks
|
||||
from notifications_utils.clients import redis
|
||||
|
||||
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
|
||||
from app.v2.errors import BadRequestError, SendNotificationToQueueError
|
||||
@@ -38,9 +37,7 @@ def persist_notification(template_id,
|
||||
job_row_number=None,
|
||||
reference=None,
|
||||
notification_id=None,
|
||||
simulated=False,
|
||||
persist=True):
|
||||
|
||||
simulated=False):
|
||||
# if simulated create a Notification model to return but do not persist the Notification to the dB
|
||||
notification = Notification(
|
||||
id=notification_id,
|
||||
@@ -59,8 +56,7 @@ def persist_notification(template_id,
|
||||
client_reference=reference
|
||||
)
|
||||
if not simulated:
|
||||
if persist:
|
||||
dao_create_notification(notification)
|
||||
dao_create_notification(notification)
|
||||
if redis_store.get(redis.daily_limit_cache_key(service.id)):
|
||||
redis_store.incr(redis.daily_limit_cache_key(service.id))
|
||||
if redis_store.get_all_from_hash(cache_key_for_service_template_counter(service.id)):
|
||||
|
||||
@@ -6,14 +6,13 @@ from flask import (
|
||||
json
|
||||
)
|
||||
|
||||
from app import api_user, encryption, create_uuid
|
||||
from app.celery import tasks
|
||||
from app import api_user
|
||||
from app.dao import (
|
||||
templates_dao,
|
||||
services_dao,
|
||||
notifications_dao
|
||||
)
|
||||
from app.models import KEY_TYPE_TEAM, PRIORITY, KEY_TYPE_TEST
|
||||
from app.models import KEY_TYPE_TEAM, PRIORITY
|
||||
from app.models import SMS_TYPE
|
||||
from app.notifications.process_client_response import (
|
||||
validate_callback_data,
|
||||
@@ -43,6 +42,7 @@ from app.errors import (
|
||||
InvalidRequest
|
||||
)
|
||||
|
||||
|
||||
register_errors(notifications)
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ def get_notification_statistics_for_day():
|
||||
|
||||
@notifications.route('/notifications/<string:notification_type>', methods=['POST'])
|
||||
def send_notification(notification_type):
|
||||
|
||||
if notification_type not in ['sms', 'email']:
|
||||
assert False
|
||||
|
||||
@@ -120,44 +121,20 @@ def send_notification(notification_type):
|
||||
|
||||
# Do not persist or send notification to the queue if it is a simulated recipient
|
||||
simulated = simulated_recipient(notification_form['to'], notification_type)
|
||||
notification_model = persist_notification(
|
||||
notification_id=create_uuid(),
|
||||
template_id=template.id,
|
||||
template_version=template.version,
|
||||
recipient=notification_form['to'],
|
||||
service=service,
|
||||
personalisation=notification_form.get('personalisation', None),
|
||||
notification_type=notification_type,
|
||||
api_key_id=api_user.id,
|
||||
key_type=api_user.key_type,
|
||||
simulated=simulated,
|
||||
persist=False)
|
||||
|
||||
notification_data = {
|
||||
'template': str(template.id),
|
||||
'template_version': template.version,
|
||||
'to': notification_form['to']
|
||||
}
|
||||
|
||||
if notification_model.personalisation:
|
||||
notification_data.update({
|
||||
'personalisation': dict(notification_model.personalisation)
|
||||
})
|
||||
encrypted = encryption.encrypt(notification_data)
|
||||
|
||||
notification_model = persist_notification(template_id=template.id,
|
||||
template_version=template.version,
|
||||
recipient=notification_form['to'],
|
||||
service=service,
|
||||
personalisation=notification_form.get('personalisation', None),
|
||||
notification_type=notification_type,
|
||||
api_key_id=api_user.id,
|
||||
key_type=api_user.key_type,
|
||||
simulated=simulated)
|
||||
if not simulated:
|
||||
tasks.send_notification_to_persist_queue(
|
||||
notification_model.id,
|
||||
service,
|
||||
template.template_type,
|
||||
encrypted,
|
||||
template.process_type == PRIORITY,
|
||||
service.research_mode or api_user.key_type == KEY_TYPE_TEST
|
||||
)
|
||||
# queue_name = 'notify' if template.process_type == PRIORITY else None
|
||||
# send_notification_to_queue(notification=notification_model,
|
||||
# research_mode=service.research_mode,
|
||||
# queue=queue_name)
|
||||
queue_name = 'notify' if template.process_type == PRIORITY else None
|
||||
send_notification_to_queue(notification=notification_model,
|
||||
research_mode=service.research_mode,
|
||||
queue=queue_name)
|
||||
else:
|
||||
current_app.logger.info("POST simulated notification for id: {}".format(notification_model.id))
|
||||
notification_form.update({"template_version": template.version})
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
from flask import request, jsonify, current_app
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from app import api_user, encryption, create_uuid
|
||||
from app.celery import tasks
|
||||
from app import api_user
|
||||
from app.dao import services_dao, templates_dao
|
||||
from app.models import SMS_TYPE, EMAIL_TYPE, PRIORITY, KEY_TYPE_TEST
|
||||
from app.models import SMS_TYPE, EMAIL_TYPE, PRIORITY
|
||||
from app.notifications.process_notifications import (create_content_for_notification,
|
||||
persist_notification,
|
||||
send_notification_to_queue,
|
||||
@@ -40,44 +39,19 @@ 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(
|
||||
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)
|
||||
|
||||
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)
|
||||
if not simulated:
|
||||
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)
|
||||
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