Skip to content

Commit

Permalink
Change provider balance on slow delivery every 5 minutes
Browse files Browse the repository at this point in the history
Instead of every 10 minutes - this way we react faster, and
fewer text messages get delayed.

This becomes more important as we now send lots of login codes
for various organisations.
  • Loading branch information
CrystalPea committed Dec 3, 2024
1 parent 7e2ebf2 commit 305bdbc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
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
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

0 comments on commit 305bdbc

Please sign in to comment.