Rewrite DAO timeout method to take cutoff_time

Previously we specified the period and calculated the cutoff time
in the function. Passing it in means we can run the method multiple
times and avoid getting "new" notifications to time out in the time
it takes to process each batch.
This commit is contained in:
Ben Thorner
2021-12-13 16:56:21 +00:00
parent b81a66da50
commit 76aeab24ce
4 changed files with 15 additions and 15 deletions

View File

@@ -161,17 +161,14 @@ def test_delete_letter_notifications_older_than_retention_calls_child_task(notif
mocked.assert_called_once_with('letter')
@freeze_time("2021-12-13T10:00")
def test_timeout_notifications(mocker, sample_notification):
mock_update = mocker.patch('app.celery.nightly_tasks.check_and_queue_callback_task')
mock_dao = mocker.patch('app.celery.nightly_tasks.dao_timeout_notifications')
mock_dao.return_value = [sample_notification]
timeout_notifications()
mock_dao.assert_called_once_with(
current_app.config.get('SENDING_NOTIFICATIONS_TIMEOUT_PERIOD')
)
mock_dao.assert_called_once_with(datetime.fromisoformat('2021-12-10T10:00'))
mock_update.assert_called_once_with(sample_notification)

View File

@@ -671,7 +671,7 @@ def test_dao_timeout_notifications(sample_template):
pending = create_notification(sample_template, status='pending')
delivered = create_notification(sample_template, status='delivered')
temporary_failure_notifications = dao_timeout_notifications(1)
temporary_failure_notifications = dao_timeout_notifications(datetime.utcnow())
assert len(temporary_failure_notifications) == 2
assert Notification.query.get(created.id).status == 'created'
@@ -687,7 +687,7 @@ def test_dao_timeout_notifications_only_updates_for_older_notifications(sample_t
pending = create_notification(sample_template, status='pending')
delivered = create_notification(sample_template, status='delivered')
temporary_failure_notifications = dao_timeout_notifications(1)
temporary_failure_notifications = dao_timeout_notifications(datetime.utcnow())
assert len(temporary_failure_notifications) == 0
assert Notification.query.get(created.id).status == 'created'
@@ -703,7 +703,7 @@ def test_dao_timeout_notifications_doesnt_affect_letters(sample_letter_template)
pending = create_notification(sample_letter_template, status='pending')
delivered = create_notification(sample_letter_template, status='delivered')
temporary_failure_notifications = dao_timeout_notifications(1)
temporary_failure_notifications = dao_timeout_notifications(datetime.utcnow())
assert len(temporary_failure_notifications) == 0
assert Notification.query.get(created.id).status == 'created'