-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lowering retry period for high priority emails to 25 seconds #2031
Changes from all commits
8d4a8f8
8b3ad4e
4b40f65
dab3a12
5ec97ae
a6a418a
fd12319
1cef267
f4a6470
17482f5
e124f21
e5bfea8
c7f6057
ec41793
e084c8f
5433518
85f5140
9e4bfe6
d064161
c3e5ee6
3b33d29
bcd3f16
4e236d4
7264ae8
cc991f2
5bf854b
2ea5a4b
e7daf30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import Any, Dict, Optional | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to move the parameters logic in its own module to avoid a circular import issue, as it was previously in a notifications init module. This would create issues. |
||
|
||
from flask import current_app | ||
|
||
from app import config, models | ||
|
||
# Default retry periods for sending notifications. | ||
RETRY_DEFAULT = 300 | ||
RETRY_HIGH = 25 | ||
|
||
|
||
class CeleryParams(object): | ||
# Important to load from the object and not the module to avoid | ||
# circular imports, back and forth between the app and celery modules. | ||
|
||
RETRY_PERIODS = { | ||
models.BULK: RETRY_DEFAULT, | ||
models.NORMAL: RETRY_DEFAULT, | ||
models.PRIORITY: RETRY_HIGH, | ||
None: RETRY_HIGH, # In case we cannot identify the priority, treat it as high. | ||
} | ||
|
||
@staticmethod | ||
def retry(notification_process_type: Optional[str] = None, countdown: Optional[int] = None) -> Dict[str, Any]: | ||
""" | ||
Build task params for the sending parameter retry 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. | ||
|
||
Provide an override parameter for cases the calling task wants to override the retry policy. | ||
""" | ||
params: dict[str, Any] = {"queue": config.QueueNames.RETRY} | ||
if current_app.config["FF_CELERY_CUSTOM_TASK_PARAMS"] is False: | ||
return params | ||
|
||
if countdown is not None: | ||
params["countdown"] = countdown | ||
else: | ||
# Overring the retry policy is only supported for SMS for now; | ||
# email support coming later. | ||
params["countdown"] = CeleryParams.RETRY_PERIODS[notification_process_type] | ||
return params |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +0,0 @@ | ||
from typing import Any, Dict | ||
|
||
from flask import current_app | ||
|
||
from app.config import QueueNames | ||
from app.models import BULK, NORMAL, PRIORITY, SMS_TYPE | ||
|
||
# Default retry periods for sending notifications. | ||
RETRY_DEFAULT = 300 | ||
RETRY_HIGH = 25 | ||
|
||
RETRY_PERIODS = { | ||
BULK: RETRY_DEFAULT, | ||
NORMAL: RETRY_DEFAULT, | ||
PRIORITY: RETRY_HIGH, | ||
} | ||
|
||
|
||
def build_retry_task_params(notification_type: str, notification_process_type: str) -> Dict[str, Any]: | ||
""" | ||
Build task params for the sending parameter retry 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: dict[str, Any] = {"queue": QueueNames.RETRY} | ||
if current_app.config["FF_CELERY_CUSTOM_TASK_PARAMS"] is False: | ||
return params | ||
|
||
# Overring the retry policy is only supported for SMS for now; | ||
# email support coming later. | ||
if notification_type == SMS_TYPE: | ||
params["countdown"] = RETRY_PERIODS[notification_process_type] | ||
else: | ||
params["countdown"] = RETRY_DEFAULT | ||
return params | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from flask import current_app | ||
|
||
from app.celery.service_callback_tasks import send_delivery_status_to_service | ||
from app.config import QueueNames | ||
from app.dao.service_callback_api_dao import ( | ||
|
@@ -6,11 +8,13 @@ | |
|
||
|
||
def _check_and_queue_callback_task(notification): | ||
if notification is None: | ||
current_app.logger.warning("No notification provided, cannot queue callback task") | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit more null protection, I think I added not part of the scope of these changes and while pairing with someone. |
||
# queue callback task only if the service_callback_api exists | ||
service_callback_api = get_service_delivery_status_callback_api_for_service(service_id=notification.service_id) | ||
if service_callback_api: | ||
notification_data = create_delivery_status_callback_data(notification, service_callback_api) | ||
|
||
send_delivery_status_to_service.apply_async([str(notification.id), notification_data], queue=QueueNames.CALLBACKS) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we add this log warning in a specific context? This is not informative of the context. Nonetheless, I added the exception to the
parameter
while logging the exception down below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was probably debugging code that slipped through