Allow 20 minutes before checking for missing rows

Since we’ve doubled the number of rows in a job, jobs can take twice as
long to insert all the notifications. We don’t check for missing rows
until we’re pretty confident that the original tasks have finished
processing. This means we need to double the time we wait to still be
as sure.
This commit is contained in:
Chris Hill-Scott
2020-09-26 11:06:44 +01:00
parent 2af62bdd1f
commit aace1bdd8a
3 changed files with 38 additions and 8 deletions

View File

@@ -398,6 +398,36 @@ def test_check_templated_letter_state_during_utc(mocker, sample_letter_template)
)
@pytest.mark.parametrize('offset', (
timedelta(days=1),
pytest.param(timedelta(hours=23, minutes=59), marks=pytest.mark.xfail),
pytest.param(timedelta(minutes=20), marks=pytest.mark.xfail),
timedelta(minutes=19),
))
def test_check_for_missing_rows_in_completed_jobs_ignores_old_and_new_jobs(
mocker,
sample_email_template,
offset,
):
mocker.patch('app.celery.tasks.s3.get_job_and_metadata_from_s3',
return_value=(load_example_csv('multiple_email'), {"sender_id": None}))
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
process_row = mocker.patch('app.celery.scheduled_tasks.process_row')
job = create_job(
template=sample_email_template,
notification_count=5,
job_status=JOB_STATUS_FINISHED,
processing_finished=datetime.utcnow() - offset,
)
for i in range(0, 4):
create_notification(job=job, job_row_number=i)
check_for_missing_rows_in_completed_jobs()
assert process_row.called is False
def test_check_for_missing_rows_in_completed_jobs(mocker, sample_email_template):
mocker.patch('app.celery.tasks.s3.get_job_and_metadata_from_s3',
return_value=(load_example_csv('multiple_email'), {"sender_id": None}))
@@ -407,7 +437,7 @@ def test_check_for_missing_rows_in_completed_jobs(mocker, sample_email_template)
job = create_job(template=sample_email_template,
notification_count=5,
job_status=JOB_STATUS_FINISHED,
processing_finished=datetime.utcnow() - timedelta(minutes=11))
processing_finished=datetime.utcnow() - timedelta(minutes=20))
for i in range(0, 4):
create_notification(job=job, job_row_number=i)
@@ -428,7 +458,7 @@ def test_check_for_missing_rows_in_completed_jobs_calls_save_email(mocker, sampl
job = create_job(template=sample_email_template,
notification_count=5,
job_status=JOB_STATUS_FINISHED,
processing_finished=datetime.utcnow() - timedelta(minutes=11))
processing_finished=datetime.utcnow() - timedelta(minutes=20))
for i in range(0, 4):
create_notification(job=job, job_row_number=i)
@@ -452,7 +482,7 @@ def test_check_for_missing_rows_in_completed_jobs_uses_sender_id(mocker, sample_
job = create_job(template=sample_email_template,
notification_count=5,
job_status=JOB_STATUS_FINISHED,
processing_finished=datetime.utcnow() - timedelta(minutes=11))
processing_finished=datetime.utcnow() - timedelta(minutes=20))
for i in range(0, 4):
create_notification(job=job, job_row_number=i)

View File

@@ -446,14 +446,14 @@ def test_find_jobs_with_missing_rows(sample_email_template):
healthy_job = create_job(template=sample_email_template,
notification_count=3,
job_status=JOB_STATUS_FINISHED,
processing_finished=datetime.utcnow() - timedelta(minutes=11)
processing_finished=datetime.utcnow() - timedelta(minutes=20)
)
for i in range(0, 3):
create_notification(job=healthy_job, job_row_number=i)
job_with_missing_rows = create_job(template=sample_email_template,
notification_count=5,
job_status=JOB_STATUS_FINISHED,
processing_finished=datetime.utcnow() - timedelta(minutes=11)
processing_finished=datetime.utcnow() - timedelta(minutes=20)
)
for i in range(0, 4):
create_notification(job=job_with_missing_rows, job_row_number=i)