Skip to content

Commit

Permalink
fix broken go live email notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Kehl committed Nov 27, 2024
1 parent 6246684 commit 1277635
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
16 changes: 11 additions & 5 deletions app/celery/provider_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from app.delivery import send_to_providers
from app.enums import NotificationStatus
from app.exceptions import NotificationTechnicalFailureException
from app.utils import utc_now
from app.utils import hilite, utc_now

# This is the amount of time to wait after sending an sms message before we check the aws logs and look for delivery
# receipts
Expand Down Expand Up @@ -170,7 +170,7 @@ def deliver_sms(self, notification_id):


@notify_celery.task(
bind=True, name="deliver_email", max_retries=48, default_retry_delay=300
bind=True, name="deliver_email", max_retries=48, default_retry_delay=30
)
def deliver_email(self, notification_id):
try:
Expand All @@ -182,9 +182,15 @@ def deliver_email(self, 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)
recipient = redis_store.get(f"email-recipient-{notification_id}")
if personalisation:
notification.personalisation = json.loads(personalisation)
if recipient:
notification.recipient = json.loads(recipient)

print(hilite(f"HERE IS THE NOTIFICATION {notification.serialize_for_csv()}"))
if recipient:
send_to_providers.send_email_to_provider(notification)
except EmailClientNonRetryableException:
current_app.logger.exception(f"Email notification {notification_id} failed")
update_notification_status_by_id(notification_id, "technical-failure")
Expand Down
13 changes: 13 additions & 0 deletions app/service/sender.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import json

from flask import current_app

from app import redis_store
from app.config import QueueNames
from app.dao.services_dao import (
dao_fetch_active_users_for_service,
Expand Down Expand Up @@ -40,7 +43,17 @@ def send_notification_to_service_users(
key_type=KeyType.NORMAL,
reply_to_text=notify_service.get_default_reply_to_email_address(),
)
redis_store.set(
f"email-personalisation-{notification.id}",
json.dumps(personalisation),
ex=24 * 60 * 60,
)
redis_store.set(
f"email-recipient-{notification.id}", notification.to, ex=24 * 60 * 60
)

send_notification_to_queue(notification, queue=QueueNames.NOTIFY)
return notification


def _add_user_fields(user, personalisation, fields):
Expand Down

0 comments on commit 1277635

Please sign in to comment.