Add a new task to update a job to error - note it leaves the notifications in whatever state they were in.

This commit is contained in:
Martyn Inglis
2017-04-18 11:42:48 +01:00
parent 6a0efd80ab
commit 8956338d31
3 changed files with 23 additions and 3 deletions

View File

@@ -36,7 +36,7 @@ from app.models import (
JOB_STATUS_IN_PROGRESS,
JOB_STATUS_FINISHED,
JOB_STATUS_READY_TO_SEND,
JOB_STATUS_SENT_TO_DVLA)
JOB_STATUS_SENT_TO_DVLA, JOB_STATUS_ERROR)
from app.notifications.process_notifications import persist_notification
from app.service.utils import service_allowed_to_send_to
from app.statsd_decorators import statsd
@@ -306,6 +306,13 @@ def update_job_to_sent_to_dvla(self, job_id):
"Updated {} job to {}".format(updated_count, job_id, JOB_STATUS_SENT_TO_DVLA))
@notify_celery.task(bind=True, name='update-letter-job-to-error')
@statsd(namespace="tasks")
def update_dvla_job_to_error(self, job_id):
dao_update_job_status(job_id, JOB_STATUS_ERROR)
current_app.logger.info("Updated {} job to {}".format(job_id, JOB_STATUS_ERROR))
def create_dvla_file_contents(job_id):
file_contents = '\n'.join(
str(LetterDVLATemplate(

View File

@@ -448,6 +448,7 @@ JOB_STATUS_SCHEDULED = 'scheduled'
JOB_STATUS_CANCELLED = 'cancelled'
JOB_STATUS_READY_TO_SEND = 'ready to send'
JOB_STATUS_SENT_TO_DVLA = 'sent to dvla'
JOB_STATUS_ERROR = 'error'
JOB_STATUS_TYPES = [
JOB_STATUS_PENDING,
JOB_STATUS_IN_PROGRESS,
@@ -456,7 +457,8 @@ JOB_STATUS_TYPES = [
JOB_STATUS_SCHEDULED,
JOB_STATUS_CANCELLED,
JOB_STATUS_READY_TO_SEND,
JOB_STATUS_SENT_TO_DVLA
JOB_STATUS_SENT_TO_DVLA,
JOB_STATUS_ERROR
]

View File

@@ -12,7 +12,7 @@ from celery.exceptions import Retry
from app import (encryption, DATETIME_FORMAT)
from app.celery import provider_tasks
from app.celery import tasks
from app.celery.tasks import s3, build_dvla_file, create_dvla_file_contents
from app.celery.tasks import s3, build_dvla_file, create_dvla_file_contents, update_dvla_job_to_error
from app.celery.tasks import (
process_job,
process_row,
@@ -1052,3 +1052,14 @@ def test_update_job_to_sent_to_dvla(sample_letter_template, sample_letter_job):
assert [(n.status == 'sending', n.sent_by == 'dvla') for n in updated_notifications]
assert 'sent to dvla' == Job.query.filter_by(id=sample_letter_job.id).one().job_status
def test_update_dvla_job_to_error(sample_letter_template, sample_letter_job):
create_notification(template=sample_letter_template, job=sample_letter_job)
create_notification(template=sample_letter_template, job=sample_letter_job)
update_dvla_job_to_error(job_id=sample_letter_job.id)
updated_notifications = Notification.query.all()
assert [(n.status == 'created', n.sent_by == 'dvla') for n in updated_notifications]
assert 'error' == Job.query.filter_by(id=sample_letter_job.id).one().job_status