Skip to content
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

Change provider balance on slow delivery every 5 minutes #4287

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/celery/scheduled_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def delete_invitations():
def switch_current_sms_provider_on_slow_delivery():
"""
Reduce provider's priority if at least 15% of notifications took more than 5 minutes to be delivered
in the last ten minutes. If both providers are slow, don't do anything. If we changed the providers in the
last ten minutes, then don't update them again either.
in the last 15 minutes. If both providers are slow, don't do anything. If we changed the providers in the
last 5 minutes, then don't update them again either.
"""
slow_delivery_notifications = is_delivery_slow_for_providers(
created_within_minutes=15,
Expand All @@ -146,7 +146,7 @@ def switch_current_sms_provider_on_slow_delivery():
for provider_name, is_slow in slow_delivery_notifications.items():
if is_slow:
current_app.logger.warning("Slow delivery notifications detected for provider %s", provider_name)
dao_reduce_sms_provider_priority(provider_name, time_threshold=timedelta(minutes=10))
dao_reduce_sms_provider_priority(provider_name, time_threshold=timedelta(minutes=5))


def _check_slow_text_message_delivery_reports_and_raise_error_if_needed(reports: list[SlowProviderDeliveryReport]):
Expand Down
6 changes: 3 additions & 3 deletions app/dao/provider_details_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ def dao_reduce_sms_provider_priority(identifier, *, time_threshold):
@autocommit
def dao_adjust_provider_priority_back_to_resting_points():
"""
Provided that neither SMS provider has been modified in the last hour, move both providers by 10 percentage points
each towards their defined resting points (set in SMS_PROVIDER_RESTING_POINTS in config.py).
Provided that neither SMS provider has been modified in the last 15 minutes, move both providers
by 10 percentage points each towards their defined resting points (set in SMS_PROVIDER_RESTING_POINTS in config.py).
"""
amount_to_reduce_by = 10
time_threshold = timedelta(hours=1)
klssmith marked this conversation as resolved.
Show resolved Hide resolved
time_threshold = timedelta(minutes=15)

providers = _get_sms_providers_for_update(time_threshold)

Expand Down
2 changes: 1 addition & 1 deletion tests/app/celery/test_scheduled_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_switch_current_sms_provider_on_slow_delivery_switches_when_one_provider
switch_current_sms_provider_on_slow_delivery()

mock_is_slow.assert_called_once_with(created_within_minutes=15, delivered_within_minutes=5, threshold=0.15)
mock_reduce.assert_called_once_with("firetext", time_threshold=timedelta(minutes=10))
mock_reduce.assert_called_once_with("firetext", time_threshold=timedelta(minutes=5))


@freeze_time("2017-05-01 14:00:00")
Expand Down
2 changes: 1 addition & 1 deletion tests/app/dao/test_provider_details_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def test_adjust_provider_priority_back_to_resting_points_updates_all_providers(

dao_adjust_provider_priority_back_to_resting_points()

mock_get_providers.assert_called_once_with(timedelta(hours=1))
mock_get_providers.assert_called_once_with(timedelta(minutes=15))
mock_adjust.assert_any_call(mmg, new_mmg)
mock_adjust.assert_any_call(firetext, new_firetext)

Expand Down