diff --git a/app/celery/scheduled_tasks.py b/app/celery/scheduled_tasks.py index 1c8d561c7..aff2ba452 100644 --- a/app/celery/scheduled_tasks.py +++ b/app/celery/scheduled_tasks.py @@ -37,7 +37,7 @@ from app.dao.notifications_dao import ( ) from app.dao.provider_details_dao import ( get_current_provider, - # dao_toggle_sms_provider + dao_toggle_sms_provider ) from app.dao.service_callback_api_dao import get_service_delivery_status_callback_api_for_service from app.dao.services_dao import ( @@ -258,7 +258,7 @@ def switch_current_sms_provider_on_slow_delivery(): """ current_provider = get_current_provider('sms') if current_provider.updated_at > datetime.utcnow() - timedelta(minutes=10): - current_app.logger.info("Slow delivery provider switched less than 10 minutes ago.") + current_app.logger.info("Slow delivery notifications provider switched less than 10 minutes ago.") return slow_delivery_notifications = is_delivery_slow_for_provider( provider=current_provider.identifier, @@ -274,7 +274,7 @@ def switch_current_sms_provider_on_slow_delivery(): ) ) - # dao_toggle_sms_provider(current_provider.identifier) + dao_toggle_sms_provider(current_provider.identifier) @notify_celery.task(name="delete-inbound-sms") diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index 654cdf691..5186e0053 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -466,8 +466,13 @@ def is_delivery_slow_for_provider( counts = {c[0]: c[1] for c in count} total_notifications = sum(counts.values()) + slow_notifications = counts.get(True, 0) + if total_notifications: - return counts.get(True, 0) / total_notifications >= threshold + current_app.logger.info("Slow delivery notifications count: {} out of {}. Ratio {}".format( + slow_notifications, total_notifications, slow_notifications / total_notifications + )) + return slow_notifications / total_notifications >= threshold else: return False diff --git a/tests/app/celery/test_scheduled_tasks.py b/tests/app/celery/test_scheduled_tasks.py index a0c621529..b2fee242a 100644 --- a/tests/app/celery/test_scheduled_tasks.py +++ b/tests/app/celery/test_scheduled_tasks.py @@ -400,7 +400,6 @@ def test_send_total_sent_notifications_to_performance_platform_calls_with_correc ]) -@pytest.mark.skip(reason="Not switching it on yet") def test_switch_providers_on_slow_delivery_switches_once_then_does_not_switch_if_already_switched( notify_api, mocker,