From af185adf4c96f50dd7b11a547680593db7610938 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Tue, 11 Dec 2018 15:28:38 +0000 Subject: [PATCH] Log the ratio of slow notifications --- app/celery/scheduled_tasks.py | 2 +- app/dao/notifications_dao.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/celery/scheduled_tasks.py b/app/celery/scheduled_tasks.py index 148749994..aff2ba452 100644 --- a/app/celery/scheduled_tasks.py +++ b/app/celery/scheduled_tasks.py @@ -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, diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index f5b733033..93592dfc2 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -467,8 +467,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