From 8d042c36f4fea6c6753024d2efe810f45c095d37 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Fri, 8 Nov 2019 10:37:37 +0000 Subject: [PATCH] Added a filter to restrict jobs older than a day from coming back. This is only necessary because there is currently a job that is old, but had 1 row created a couple days later. So now there is 1 notifications for the job where the rest have been purged. --- app/dao/jobs_dao.py | 5 ++++- tests/app/dao/test_jobs_dao.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/dao/jobs_dao.py b/app/dao/jobs_dao.py index a5a7411f1..ad447f484 100644 --- a/app/dao/jobs_dao.py +++ b/app/dao/jobs_dao.py @@ -194,13 +194,16 @@ def find_jobs_with_missing_rows(): # Jobs can be a maximum of 50,000 rows. It typically takes 5 minutes to create all those notifications. # Using 10 minutes as a condition seems reasonable. ten_minutes_ago = datetime.utcnow() - timedelta(minutes=10) + yesterday = datetime.utcnow() - timedelta(days=1) jobs_with_rows_missing = db.session.query( func.count(Notification.id).label('actual_count'), Job ).filter( Job.job_status == JOB_STATUS_FINISHED, Job.processing_finished < ten_minutes_ago, - Job.id == Notification.job_id + Job.processing_finished > yesterday, + Job.id == Notification.job_id, + ).group_by( Job ).having( diff --git a/tests/app/dao/test_jobs_dao.py b/tests/app/dao/test_jobs_dao.py index 704973bfe..d8905ebc3 100644 --- a/tests/app/dao/test_jobs_dao.py +++ b/tests/app/dao/test_jobs_dao.py @@ -454,6 +454,22 @@ def test_find_jobs_with_missing_rows_returns_nothing_for_a_job_completed_less_th assert len(results) == 0 +def test_find_jobs_with_missing_rows_returns_nothing_for_a_job_completed_more_that_a_day_ago( + sample_email_template +): + job = create_job(template=sample_email_template, + notification_count=5, + job_status=JOB_STATUS_FINISHED, + processing_finished=datetime.utcnow() - timedelta(days=1) + ) + for i in range(0, 4): + create_notification(job=job, job_row_number=i) + + results = find_jobs_with_missing_rows() + + assert len(results) == 0 + + @pytest.mark.parametrize('status', ['pending', 'in progress', 'cancelled', 'scheduled']) def test_find_jobs_with_missing_rows_doesnt_return_jobs_that_are_not_finished( sample_email_template, status