Skip to content

Commit

Permalink
Merge pull request #1443 from GSA/notify-api-1442
Browse files Browse the repository at this point in the history
fix broken go live email notification
  • Loading branch information
ccostino authored Dec 2, 2024
2 parents 7a90722 + a5b83f5 commit fe033b0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/celery/provider_tasks.py
Original file line number Diff line number Diff line change
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,8 +182,12 @@ def deliver_email(self, notification_id):
if not notification:
raise NoResultFound()
personalisation = redis_store.get(f"email-personalisation-{notification_id}")
recipient = redis_store.get(f"email-recipient-{notification_id}")
if personalisation:
notification.personalisation = json.loads(personalisation)
if recipient:
notification.recipient = json.loads(recipient)

notification.personalisation = json.loads(personalisation)
send_to_providers.send_email_to_provider(notification)
except EmailClientNonRetryableException:
current_app.logger.exception(f"Email notification {notification_id} failed")
Expand Down
12 changes: 12 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,6 +43,15 @@ 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)


Expand Down
4 changes: 4 additions & 0 deletions tests/app/service/test_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def test_send_notification_to_service_users_includes_user_fields_in_personalisat
):
persist_mock = mocker.patch("app.service.sender.persist_notification")
mocker.patch("app.service.sender.send_notification_to_queue")
mocker.patch("app.service.sender.redis_store")

user = sample_service.users[0]

Expand All @@ -82,13 +83,16 @@ def test_send_notification_to_service_users_sends_to_active_users_only(
notify_service, mocker
):
mocker.patch("app.service.sender.send_notification_to_queue")
mocker.patch("app.service.sender.redis_store", autospec=True)

first_active_user = create_user(email="[email protected]", state="active")
second_active_user = create_user(email="[email protected]", state="active")
pending_user = create_user(email="[email protected]", state="pending")
service = create_service(user=first_active_user)
dao_add_user_to_service(service, second_active_user)

dao_add_user_to_service(service, pending_user)

template = create_template(service, template_type=TemplateType.EMAIL)

send_notification_to_service_users(service_id=service.id, template_id=template.id)
Expand Down

0 comments on commit fe033b0

Please sign in to comment.