diff --git a/app/celery/provider_tasks.py b/app/celery/provider_tasks.py index 3610126d4..47e4c0bd8 100644 --- a/app/celery/provider_tasks.py +++ b/app/celery/provider_tasks.py @@ -1,10 +1,11 @@ +import json import os from datetime import datetime, timedelta from flask import current_app from sqlalchemy.orm.exc import NoResultFound -from app import aws_cloudwatch_client, notify_celery +from app import aws_cloudwatch_client, notify_celery, redis_store from app.clients.email import EmailClientNonRetryableException from app.clients.email.aws_ses import AwsSesClientThrottlingSendRateException from app.clients.sms import SmsClientResponseException @@ -162,8 +163,12 @@ def deliver_email(self, notification_id): "Start sending email for notification id: {}".format(notification_id) ) notification = notifications_dao.get_notification_by_id(notification_id) + if not notification: raise NoResultFound() + personalisation = redis_store.get(f"email-personalisation-{notification_id}") + + notification.personalisation = json.loads(personalisation) send_to_providers.send_email_to_provider(notification) except EmailClientNonRetryableException as e: current_app.logger.exception( diff --git a/app/user/rest.py b/app/user/rest.py index 507e6c9e0..58a3d8e24 100644 --- a/app/user/rest.py +++ b/app/user/rest.py @@ -437,6 +437,11 @@ def send_new_user_email_verification(user_id): str(user_to_send_to.email_address), ex=60 * 60, ) + redis_store.set( + f"email-personalisation-{saved_notification.id}", + json.dumps(personalisation), + ex=60 * 60, + ) current_app.logger.info("Sending notification to queue") send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)