Skip to content

Commit

Permalink
Overriding retry policy for SMS high priority
Browse files Browse the repository at this point in the history
  • Loading branch information
jimleroyer committed Oct 24, 2023
1 parent 86be8bc commit d5ce6a2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
26 changes: 26 additions & 0 deletions app/notifications/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from app.models import BULK, NORMAL, PRIORITY

# Default retry policy for all notifications.
RETRY_POLICY_DEFAULT = {
"max_retries": 48,
"interval_start": 300,
"interval_step": 300,
"interval_max": 300,
"retry_errors": None,
}

# Retry policy for high priority notifications.
RETRY_POLICY_HIGH = {
"max_retries": 48,
"interval_start": 25,
"interval_step": 25,
"interval_max": 25,
"retry_errors": None,
}

# Retry policies for each notification priority lanes.
RETRY_POLICIES = {
BULK: RETRY_POLICY_DEFAULT,
NORMAL: RETRY_POLICY_DEFAULT,
PRIORITY: RETRY_POLICY_HIGH,
}
21 changes: 20 additions & 1 deletion app/notifications/process_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
ScheduledNotification,
Service,
)
from app.notifications import RETRY_POLICY_DEFAULT, RETRY_POLICIES
from app.types import VerifiedNotification
from app.utils import get_delivery_queue_for_template, get_template_instance
from app.v2.errors import BadRequestError
Expand Down Expand Up @@ -210,7 +211,7 @@ def db_save_and_send_notification(notification: Notification):

deliver_task = choose_deliver_task(notification)
try:
deliver_task.apply_async([str(notification.id)], queue=notification.queue_name)
deliver_task.apply_async([str(notification.id)], queue=notification.queue_name, **build_task_params(notification))
except Exception:
dao_delete_notifications_by_id(notification.id)
raise
Expand All @@ -219,6 +220,24 @@ def db_save_and_send_notification(notification: Notification):
)


def build_task_params(notification: Notification):
"""
Build task params for the sending parameter tasks.
If the notification is a high priority SMS, set the retry policy to retry every 25 seconds
else fall back to the default retry policy of retrying every 5 minutes.
"""
params = {}
params['retry'] = True
# Overring the retry policy is only supported for SMS for now;
# email support coming later.
if notification.notification_type == SMS_TYPE:
params['retry_policy'] = RETRY_POLICIES[notification.template.process_type]
else:
params['retry_policy'] = RETRY_POLICY_DEFAULT
return params


def choose_queue(notification, research_mode, queue=None) -> QueueNames:
if research_mode or notification.key_type == KEY_TYPE_TEST:
queue = QueueNames.RESEARCH_MODE
Expand Down

0 comments on commit d5ce6a2

Please sign in to comment.