Process Incomplete Jobs Updates

Comments are PR review. Updated code style in a few places to make it
more consistent with other code, added tests for letters and emails
so they are testedt, refactored some database queries to dao file

- Fixed code style
- Refactored database queries to dao code
- Added tests for emails and sms.
This commit is contained in:
Richard Chapman
2017-10-17 11:07:36 +01:00
parent 0ff80bcb76
commit 543535e2af
6 changed files with 129 additions and 33 deletions

View File

@@ -37,8 +37,8 @@ from app.dao.jobs_dao import (
from app.dao.notifications_dao import (
get_notification_by_id,
dao_update_notifications_for_job_to_sent_to_dvla,
dao_update_notifications_by_reference
)
dao_update_notifications_by_reference,
dao_get_last_notification_added_for_job_id)
from app.dao.provider_details_dao import get_current_provider
from app.dao.service_inbound_api_dao import get_service_inbound_api_for_service
from app.dao.services_dao import dao_fetch_service_by_id, fetch_todays_total_message_count
@@ -47,13 +47,13 @@ from app.models import (
Job,
Notification,
EMAIL_TYPE,
KEY_TYPE_NORMAL,
JOB_STATUS_CANCELLED,
JOB_STATUS_PENDING,
JOB_STATUS_IN_PROGRESS,
JOB_STATUS_FINISHED,
JOB_STATUS_IN_PROGRESS,
JOB_STATUS_PENDING,
JOB_STATUS_READY_TO_SEND,
JOB_STATUS_SENT_TO_DVLA, JOB_STATUS_ERROR,
KEY_TYPE_NORMAL,
LETTER_TYPE,
NOTIFICATION_SENDING,
NOTIFICATION_TECHNICAL_FAILURE,
@@ -109,11 +109,11 @@ def process_job(job_id):
).enumerated_recipients_and_personalisation:
process_row(row_number, recipient, personalisation, template, job, service)
job_complete(job, service, template, False, start)
job_complete(job, service, template.template_type, start=start)
def job_complete(job, service, template, resumed, start=None):
if template.template_type == LETTER_TYPE:
def job_complete(job, service, template_type, resumed=False, start=None):
if template_type == LETTER_TYPE:
if service.research_mode:
update_job_to_sent_to_dvla.apply_async([str(job.id)], queue=QueueNames.RESEARCH_MODE)
else:
@@ -506,13 +506,9 @@ def process_incomplete_jobs(job_ids):
def process_incomplete_job(job_id):
job = Job.query.filter(Job.id == job_id).one()
job = dao_get_job_by_id(job_id)
last_notification_added = Notification.query.filter(
Notification.job_id == job_id
).order_by(
Notification.job_row_number.desc()
).first()
last_notification_added = dao_get_last_notification_added_for_job_id(job_id)
if last_notification_added:
resume_from_row = last_notification_added.job_row_number
@@ -534,4 +530,4 @@ def process_incomplete_job(job_id):
if row_number > resume_from_row:
process_row(row_number, recipient, personalisation, template, job, job.service)
job_complete(job, job.service, template, True)
job_complete(job, job.service, template, resumed=True)