Add scheduled task to find old letters which still have 'created' status

Added a scheduled task to run once a day and check if there were any
letters from before 17.30 that still have a status of 'created'. This
logs an exception instead of trying to fix the error because the fix
will be different depending on which bucket the letter is in.
This commit is contained in:
Katie Smith
2019-06-11 15:13:06 +01:00
parent a2f324ad7e
commit c518f6ca76
4 changed files with 74 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ from app.dao.notifications_dao import (
set_scheduled_notification_to_processed,
notifications_not_yet_sent,
dao_precompiled_letters_still_pending_virus_check,
dao_old_letters_with_created_status,
)
from app.dao.provider_details_dao import (
get_current_provider,
@@ -193,3 +194,17 @@ def check_precompiled_letter_state():
len(letters),
letter_ids)
)
@notify_celery.task(name='check-templated-letter-state')
@statsd(namespace="tasks")
def check_templated_letter_state():
letters = dao_old_letters_with_created_status()
letter_ids = [str(letter.id) for letter in letters]
if len(letters) > 0:
current_app.logger.exception(
"{} letters were created before 17.30 yesterday and still have 'created' state. Notifications: {}".format(
len(letters),
letter_ids)
)