Add new task to alert about created email / sms

This will log an error when email or SMS notifications have been
stuck in 'created' for too long - normally they should be 'sending'
in seconds, noting that we have a goal of < 10s wait time for most
notifications being processed our platform.

In the next commits we'll decouple similar functionality from the
existing 'timeout-sending-notifications' task.
This commit is contained in:
Ben Thorner
2021-11-24 13:47:48 +00:00
parent a8cad79def
commit f96ba5361a
5 changed files with 77 additions and 0 deletions

View File

@@ -512,6 +512,16 @@ def _timeout_notifications(current_statuses, new_status, timeout_start, updated_
return notifications
def dao_check_notifications_still_in_created(minimum_age_in_seconds):
min_created_at = datetime.utcnow() - timedelta(seconds=minimum_age_in_seconds)
return Notification.query.filter(
Notification.created_at < min_created_at,
Notification.status == NOTIFICATION_CREATED,
Notification.notification_type.in_([SMS_TYPE, EMAIL_TYPE])
).count()
def dao_timeout_notifications(timeout_period_in_seconds):
"""
Timeout SMS and email notifications by the following rules: