mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
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:
@@ -8,6 +8,7 @@ from sqlalchemy.exc import IntegrityError, SQLAlchemyError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from app.dao.notifications_dao import (
|
||||
dao_check_notifications_still_in_created,
|
||||
dao_create_notification,
|
||||
dao_delete_notifications_by_id,
|
||||
dao_get_last_notification_added_for_job_id,
|
||||
@@ -664,6 +665,33 @@ def _notification_json(sample_template, job_id=None, id=None, status=None):
|
||||
return data
|
||||
|
||||
|
||||
def test_dao_check_notifications_still_in_created(
|
||||
sample_template,
|
||||
sample_email_template,
|
||||
sample_letter_template
|
||||
):
|
||||
with freeze_time(datetime.utcnow() - timedelta(minutes=2)):
|
||||
# old sending notification (ignored)
|
||||
create_notification(sample_template, status='sending')
|
||||
# old letter notification (ignored)
|
||||
create_notification(sample_letter_template, status='created')
|
||||
|
||||
with freeze_time(datetime.utcnow() + timedelta(minutes=10)):
|
||||
# new / future notification (ignored)
|
||||
create_notification(sample_template, status='created')
|
||||
|
||||
# first prove all the above notifications are ignored
|
||||
assert dao_check_notifications_still_in_created(1) == 0
|
||||
|
||||
with freeze_time(datetime.utcnow() - timedelta(minutes=2)):
|
||||
# now add old, eligible notifications
|
||||
create_notification(sample_template, status='created')
|
||||
create_notification(sample_email_template, status='created')
|
||||
|
||||
# now prove the check only picks up on these ones
|
||||
assert dao_check_notifications_still_in_created(1) == 2
|
||||
|
||||
|
||||
def test_dao_timeout_notifications(sample_template):
|
||||
with freeze_time(datetime.utcnow() - timedelta(minutes=2)):
|
||||
created = create_notification(sample_template, status='created')
|
||||
|
||||
Reference in New Issue
Block a user