-
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
8d4a8f8
Decoupled scan malware code + lowering retry period for high priority…
jimleroyer 8b3ad4e
Extract common email retry handling logic into its own function
jimleroyer 4b40f65
Cleaned up import
jimleroyer dab3a12
Forgot to provide default value to optional fn arg
jimleroyer 5ec97ae
Fixed test import
jimleroyer a6a418a
Isolated retry task param builder in a class
jimleroyer fd12319
Merge remote-tracking branch 'origin/main' into feat/decrease-retry-f…
jimleroyer 1cef267
Cleaned up import
jimleroyer f4a6470
Fixed moved refs
jimleroyer 17482f5
Trying a different strategy to fix circular import
jimleroyer e124f21
Fixing another bad import ref
jimleroyer e5bfea8
Introducing celery utils module instead of using celery root one
jimleroyer c7f6057
Merge remote-tracking branch 'origin/main' into feat/decrease-retry-f…
jimleroyer ec41793
Cover edge cases + modified tests
jimleroyer e084c8f
Merge remote-tracking branch 'origin/main' into feat/decrease-retry-f…
jimleroyer 5433518
Formatting
jimleroyer 85f5140
Sort imports
jimleroyer 9e4bfe6
Make notification_process_type param optional
jimleroyer d064161
Merge remote-tracking branch 'origin/main' into feat/decrease-retry-f…
jimleroyer c3e5ee6
Fixed edge case when template not associated with notification obj
jimleroyer 3b33d29
Merge remote-tracking branch 'origin/main' into feat/decrease-retry-f…
jimleroyer bcd3f16
Fixing params order
jimleroyer 4e236d4
Fixing regression tests
jimleroyer 7264ae8
More tests
jimleroyer cc991f2
Added null protection against a potential NPE
jimleroyer 5bf854b
Formatting
jimleroyer 2ea5a4b
Fix imports
jimleroyer e7daf30
Merge branch 'main' into feat/decrease-retry-for-email-high
sastels File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from typing import Any, Dict, Optional | ||
|
||
from flask import current_app | ||
|
||
from app.config import QueueNames | ||
from app.models import BULK, NORMAL, PRIORITY | ||
|
||
# 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, countdown: Optional[int]) -> 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": 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"] = RETRY_PERIODS[notification_process_type] | ||
|
||
return params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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