mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-12 00:02:36 -05:00
Add a task for the FTP app to call that will update the job to sent to dvla and all the notifications for that job as sending.
This commit is contained in:
@@ -24,7 +24,8 @@ from app.dao.jobs_dao import (
|
||||
all_notifications_are_created_for_job,
|
||||
dao_get_all_notifications_for_job,
|
||||
dao_update_job_status)
|
||||
from app.dao.notifications_dao import get_notification_by_id
|
||||
from app.dao.notifications_dao import get_notification_by_id, dao_update_notification
|
||||
from app.dao.provider_details_dao import get_current_provider
|
||||
from app.dao.services_dao import dao_fetch_service_by_id, fetch_todays_total_message_count
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.models import (
|
||||
@@ -32,7 +33,12 @@ from app.models import (
|
||||
SMS_TYPE,
|
||||
LETTER_TYPE,
|
||||
KEY_TYPE_NORMAL,
|
||||
JOB_STATUS_CANCELLED, JOB_STATUS_PENDING, JOB_STATUS_IN_PROGRESS, JOB_STATUS_FINISHED, JOB_STATUS_READY_TO_SEND)
|
||||
JOB_STATUS_CANCELLED,
|
||||
JOB_STATUS_PENDING,
|
||||
JOB_STATUS_IN_PROGRESS,
|
||||
JOB_STATUS_FINISHED,
|
||||
JOB_STATUS_READY_TO_SEND,
|
||||
JOB_STATUS_SENT_TO_DVLA, NOTIFICATION_SENDING)
|
||||
from app.notifications.process_notifications import persist_notification
|
||||
from app.service.utils import service_allowed_to_send_to
|
||||
from app.statsd_decorators import statsd
|
||||
@@ -286,19 +292,34 @@ def build_dvla_file(self, job_id):
|
||||
raise e
|
||||
|
||||
|
||||
@notify_celery.task(bind=True, name='update-letter-job-to-sent')
|
||||
@statsd(namespace="tasks")
|
||||
def update_job_to_sent_to_dvla(self, job_id):
|
||||
# This task will be called by the FTP app to update the job to sent to dvla
|
||||
# and update all notifications for this job to sending, provider = DVLA
|
||||
provider = get_current_provider(LETTER_TYPE)
|
||||
notifications = dao_get_all_notifications_for_job(job_id)
|
||||
for n in notifications:
|
||||
n.status = NOTIFICATION_SENDING
|
||||
n.sent_by = provider.identifier
|
||||
dao_update_notification(n)
|
||||
|
||||
dao_update_job_status(job_id, JOB_STATUS_SENT_TO_DVLA)
|
||||
|
||||
|
||||
def create_dvla_file_contents(job_id):
|
||||
file_contents = '\n'.join(
|
||||
str(LetterDVLATemplate(
|
||||
notification.template.__dict__,
|
||||
notification.personalisation,
|
||||
# This unique id is a 7 digits requested by DVLA, not known
|
||||
# if this number needs to be sequential.
|
||||
numeric_id=random.randint(1, int('9' * 7)),
|
||||
contact_block=notification.service.letter_contact_block,
|
||||
))
|
||||
for notification in dao_get_all_notifications_for_job(job_id)
|
||||
)
|
||||
return file_contents
|
||||
file_contents = '\n'.join(
|
||||
str(LetterDVLATemplate(
|
||||
notification.template.__dict__,
|
||||
notification.personalisation,
|
||||
# This unique id is a 7 digits requested by DVLA, not known
|
||||
# if this number needs to be sequential.
|
||||
numeric_id=random.randint(1, int('9' * 7)),
|
||||
contact_block=notification.service.letter_contact_block,
|
||||
))
|
||||
for notification in dao_get_all_notifications_for_job(job_id)
|
||||
)
|
||||
return file_contents
|
||||
|
||||
|
||||
def s3upload(filedata, region, bucket_name, file_location):
|
||||
|
||||
Reference in New Issue
Block a user