In this PR we remove trigger-letter-pdfs-for-day scheduled task and just call collate_letter_pdfs_for_day instead.

There was a datetime bug in the query which resulted in files not being sent to the postal provider.
The trigger-letter-pdfs-for-day task is no longer needed, so rather than fix the query just call collate_letter_pdfs_for_day directly.
Less code is always better.

Deployment considerations: I realized this is strictly not backwards compatible if the scheduled job is in progress and a task is on the queue that no longer exists. This is ok since we will deploy this well before 17:50.
This commit is contained in:
Rebecca Law
2018-09-12 17:16:34 +01:00
parent ae1ee85d12
commit f1b04193ca
7 changed files with 18 additions and 156 deletions

View File

@@ -199,6 +199,14 @@ def test_collate_letter_pdfs_for_day(notify_api, mocker):
)
@freeze_time('2018-09-12 17:50:00')
def test_collate_letter_pdfs_for_day_works_without_date_param(notify_api, mocker):
mock_s3 = mocker.patch('app.celery.tasks.s3.get_s3_bucket_objects')
collate_letter_pdfs_for_day()
expected_date = '2018-09-12'
mock_s3.assert_called_once_with('test-letters-pdf', subfolder=expected_date)
def test_group_letters_splits_on_file_size(notify_api, mocker):
mocker.patch('app.celery.letters_pdf_tasks.letter_in_created_state', return_value=True)
letters = [

View File

@@ -26,7 +26,6 @@ from app.celery.scheduled_tasks import (
remove_transformed_dvla_files,
run_scheduled_jobs,
run_letter_jobs,
trigger_letter_pdfs_for_day,
s3,
send_daily_performance_platform_stats,
send_scheduled_notifications,
@@ -763,32 +762,6 @@ def test_run_letter_jobs(client, mocker, sample_letter_template):
queue=QueueNames.PROCESS_FTP)
@freeze_time("2017-12-18 17:50")
def test_trigger_letter_pdfs_for_day(client, mocker, sample_letter_template):
create_notification(template=sample_letter_template, created_at='2017-12-17 17:30:00')
create_notification(template=sample_letter_template, created_at='2017-12-18 17:29:59')
mock_celery = mocker.patch("app.celery.tasks.notify_celery.send_task")
trigger_letter_pdfs_for_day()
mock_celery.assert_called_once_with(name='collate-letter-pdfs-for-day',
args=('2017-12-18',),
queue=QueueNames.LETTERS)
@freeze_time("2017-12-18 17:50")
def test_trigger_letter_pdfs_for_day_send_task_not_called_if_no_notis_for_day(
client, mocker, sample_letter_template):
create_notification(template=sample_letter_template, created_at='2017-12-15 17:30:00')
mock_celery = mocker.patch("app.celery.tasks.notify_celery.send_task")
trigger_letter_pdfs_for_day()
assert not mock_celery.called
def test_run_letter_jobs_does_nothing_if_no_ready_jobs(client, mocker, sample_letter_template):
create_job(sample_letter_template, job_status=JOB_STATUS_IN_PROGRESS)
create_job(sample_letter_template, job_status=JOB_STATUS_SENT_TO_DVLA)

View File

@@ -10,7 +10,6 @@ from app.dao.notifications_dao import (
dao_create_notification,
dao_created_scheduled_notification,
dao_delete_notifications_and_history_by_id,
dao_get_count_of_letters_to_process_for_date,
dao_get_last_notification_added_for_job_id,
dao_get_last_template_usage,
dao_get_notifications_by_to_field,
@@ -1760,82 +1759,6 @@ def test_dao_get_notification_history_by_reference_with_no_matches_raises_error(
dao_get_notification_history_by_reference('REF1')
@freeze_time("2017-12-18 17:50")
def test_dao_get_count_of_letters_to_process_for_today(sample_letter_template):
# expected
create_notification(template=sample_letter_template, created_at='2017-12-17 17:30:00')
create_notification(template=sample_letter_template, created_at='2017-12-18 17:29:59')
# not expected
create_notification(template=sample_letter_template, created_at='2017-12-17 17:29:59')
create_notification(template=sample_letter_template, created_at='2017-12-18 17:30:00')
count_for_date = dao_get_count_of_letters_to_process_for_date()
assert count_for_date == 2
@freeze_time("2017-12-18 17:50")
def test_dao_get_count_of_letters_to_process_for_date_in_past(sample_letter_template):
# expected
create_notification(template=sample_letter_template, created_at='2017-12-15 17:29:59')
# not expected
create_notification(template=sample_letter_template, created_at='2017-12-15 17:30:00')
create_notification(template=sample_letter_template, created_at='2017-12-18 17:29:00')
count_for_date = dao_get_count_of_letters_to_process_for_date(date(2017, 12, 15))
assert count_for_date == 1
@freeze_time("2017-12-18 17:50")
def test_dao_get_count_of_letters_to_process_for_date_in_future_does_not_raise_error(sample_letter_template):
# not expected
create_notification(template=sample_letter_template, created_at='2017-12-18 17:30:00')
create_notification(template=sample_letter_template, created_at='2017-12-19 17:29:59')
count_for_date = dao_get_count_of_letters_to_process_for_date(date(2017, 12, 20))
assert count_for_date == 0
def test_dao_get_count_of_letters_to_process_for_today_without_notis_does_not_raise_error(sample_letter_template):
count_for_date = dao_get_count_of_letters_to_process_for_date()
assert count_for_date == 0
@freeze_time("2017-12-18 17:50")
def test_dao_get_count_of_letters_to_process_for_date_ignores_research_mode_services(sample_letter_template):
research_service = create_service(service_name='research service', research_mode=True)
research_template = create_template(research_service, template_type='letter')
# not expected
create_notification(template=research_template, created_at='2017-12-18 17:29:00')
# expected
create_notification(template=sample_letter_template, created_at='2017-12-18 17:29:10')
create_notification(template=sample_letter_template, created_at='2017-12-18 17:29:20')
count_for_date = dao_get_count_of_letters_to_process_for_date()
assert count_for_date == 2
@freeze_time("2017-12-18 17:50")
def test_dao_get_count_of_letters_to_process_for_date_ignores_test_keys(sample_letter_template):
# not expected
create_notification(template=sample_letter_template, key_type=KEY_TYPE_TEST, created_at='2017-12-18 17:29:00')
# expected
create_notification(template=sample_letter_template, created_at='2017-12-18 17:29:10')
create_notification(template=sample_letter_template, created_at='2017-12-18 17:29:20')
count_for_date = dao_get_count_of_letters_to_process_for_date()
assert count_for_date == 2
@pytest.mark.parametrize("notification_type",
["letter", "email", "sms"]
)