From f097abe82b47a6d174eb75191015e865a890c0ea Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Fri, 16 Aug 2019 10:37:51 +0100 Subject: [PATCH] Change the query to get the notifications for the `check_templated_letter_state`. Now looking at the updated_at date, we are getting the alert if the notification was created_at:17:29 updated to created status at 17:30, so the letter is in the next days bucket. Not sure if I want to make this change, there isn't an index on updated_at, so the query might be slow. --- app/dao/notifications_dao.py | 4 ++-- tests/app/celery/test_scheduled_tasks.py | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index 84f9e1249..8976bbebc 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -689,11 +689,11 @@ def dao_old_letters_with_created_status(): last_processing_deadline = yesterday_bst.replace(hour=17, minute=30, second=0, microsecond=0) notifications = Notification.query.filter( - Notification.created_at < convert_bst_to_utc(last_processing_deadline), + Notification.updated_at < convert_bst_to_utc(last_processing_deadline), Notification.notification_type == LETTER_TYPE, Notification.status == NOTIFICATION_CREATED ).order_by( - Notification.created_at + Notification.updated_at ).all() return notifications diff --git a/tests/app/celery/test_scheduled_tasks.py b/tests/app/celery/test_scheduled_tasks.py index baf108380..f6081916f 100644 --- a/tests/app/celery/test_scheduled_tasks.py +++ b/tests/app/celery/test_scheduled_tasks.py @@ -376,12 +376,12 @@ def test_check_templated_letter_state_during_bst(mocker, sample_letter_template) mock_logger = mocker.patch('app.celery.tasks.current_app.logger.exception') mock_create_ticket = mocker.patch('app.celery.nightly_tasks.zendesk_client.create_ticket') - noti_1 = create_notification(template=sample_letter_template, created_at=datetime(2019, 5, 1, 12, 0)) - noti_2 = create_notification(template=sample_letter_template, created_at=datetime(2019, 5, 29, 16, 29)) - create_notification(template=sample_letter_template, created_at=datetime(2019, 5, 29, 16, 30)) - create_notification(template=sample_letter_template, created_at=datetime(2019, 5, 29, 17, 29)) - create_notification(template=sample_letter_template, status='delivered', created_at=datetime(2019, 5, 28, 10, 0)) - create_notification(template=sample_letter_template, created_at=datetime(2019, 5, 30, 10, 0)) + noti_1 = create_notification(template=sample_letter_template, updated_at=datetime(2019, 5, 1, 12, 0)) + noti_2 = create_notification(template=sample_letter_template, updated_at=datetime(2019, 5, 29, 16, 29)) + create_notification(template=sample_letter_template, updated_at=datetime(2019, 5, 29, 16, 30)) + create_notification(template=sample_letter_template, updated_at=datetime(2019, 5, 29, 17, 29)) + create_notification(template=sample_letter_template, status='delivered', updated_at=datetime(2019, 5, 28, 10, 0)) + create_notification(template=sample_letter_template, updated_at=datetime(2019, 5, 30, 10, 0)) check_templated_letter_state() @@ -401,12 +401,12 @@ def test_check_templated_letter_state_during_utc(mocker, sample_letter_template) mock_logger = mocker.patch('app.celery.tasks.current_app.logger.exception') mock_create_ticket = mocker.patch('app.celery.nightly_tasks.zendesk_client.create_ticket') - noti_1 = create_notification(template=sample_letter_template, created_at=datetime(2018, 12, 1, 12, 0)) - noti_2 = create_notification(template=sample_letter_template, created_at=datetime(2019, 1, 29, 17, 29)) - create_notification(template=sample_letter_template, created_at=datetime(2019, 1, 29, 17, 30)) - create_notification(template=sample_letter_template, created_at=datetime(2019, 1, 29, 18, 29)) - create_notification(template=sample_letter_template, status='delivered', created_at=datetime(2019, 1, 29, 10, 0)) - create_notification(template=sample_letter_template, created_at=datetime(2019, 1, 30, 10, 0)) + noti_1 = create_notification(template=sample_letter_template, updated_at=datetime(2018, 12, 1, 12, 0)) + noti_2 = create_notification(template=sample_letter_template, updated_at=datetime(2019, 1, 29, 17, 29)) + create_notification(template=sample_letter_template, updated_at=datetime(2019, 1, 29, 17, 30)) + create_notification(template=sample_letter_template, updated_at=datetime(2019, 1, 29, 18, 29)) + create_notification(template=sample_letter_template, status='delivered', updated_at=datetime(2019, 1, 29, 10, 0)) + create_notification(template=sample_letter_template, updated_at=datetime(2019, 1, 30, 10, 0)) check_templated_letter_state()