Add a task to save-api-sms for high volume services.

When we initially added a new task to persist the notifications for a high volume service we wanted to implement it as quickly as possible, so ignored SMS.
This will allow a high volume service to send SMS, the SMS will be sent to a queue to then persist and send the SMS, similar to emails.

At this point I haven't added a new application to consume the new save-api-sms-tasks. But we can add a separate application or be happy with how the app scales for both email and sms.
This commit is contained in:
Rebecca Law
2020-10-19 13:29:05 +01:00
parent d9ceed55b5
commit 3dee4ad310
7 changed files with 126 additions and 76 deletions

View File

@@ -18,7 +18,7 @@ from app import (
)
from app.celery.letters_pdf_tasks import get_pdf_for_templated_letter, sanitise_letter
from app.celery.research_mode_tasks import create_fake_letter_response_file
from app.celery.tasks import save_api_email
from app.celery.tasks import save_api_email, save_api_sms
from app.clients.document_download import DocumentDownloadError
from app.config import QueueNames, TaskNames
from app.dao.templates_dao import get_precompiled_letter_template
@@ -201,14 +201,13 @@ def process_sms_or_email_notification(
template_with_content=template_with_content
)
if service.id in current_app.config.get('HIGH_VOLUME_SERVICE') and api_user.key_type == KEY_TYPE_NORMAL \
and notification_type == EMAIL_TYPE:
if service.id in current_app.config.get('HIGH_VOLUME_SERVICE') and api_user.key_type == KEY_TYPE_NORMAL:
# Put GOV.UK Email notifications onto a queue
# To take the pressure off the db for API requests put the notification for our high volume service onto a queue
# the task will then save the notification, then call send_notification_to_queue.
# We know that this team does not use the GET request, but relies on callbacks to get the status updates.
try:
save_email_to_queue(
save_email_or_sms_to_queue(
form=form,
notification_id=str(notification_id),
notification_type=notification_type,
@@ -258,7 +257,7 @@ def process_sms_or_email_notification(
return resp
def save_email_to_queue(
def save_email_or_sms_to_queue(
*,
notification_id,
form,
@@ -274,7 +273,7 @@ def save_email_to_queue(
"id": notification_id,
"template_id": str(template.id),
"template_version": template.version,
"to": form['email_address'],
"to": form['email_address'] if notification_type == EMAIL_TYPE else form['phone_number'],
"service_id": str(service_id),
"personalisation": personalisation,
"notification_type": notification_type,
@@ -290,7 +289,11 @@ def save_email_to_queue(
data
)
save_api_email.apply_async([encrypted], queue=QueueNames.SAVE_API_EMAIL)
if notification_type == EMAIL_TYPE:
save_api_email.apply_async([encrypted], queue=QueueNames.SAVE_API_EMAIL)
else:
save_api_sms.apply_async([encrypted], queue=QueueNames.SAVE_API_SMS)
return Notification(**data)