mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 05:28:49 -04:00
Merge pull request #863 from alphagov/create-dvla-file
Added logging for any exception thrown in build_dvla_file
This commit is contained in:
@@ -265,22 +265,26 @@ def persist_letter(
|
|||||||
@notify_celery.task(bind=True, name="build-dvla-file", max_retries=15, default_retry_delay=300)
|
@notify_celery.task(bind=True, name="build-dvla-file", max_retries=15, default_retry_delay=300)
|
||||||
@statsd(namespace="tasks")
|
@statsd(namespace="tasks")
|
||||||
def build_dvla_file(self, job_id):
|
def build_dvla_file(self, job_id):
|
||||||
if all_notifications_are_created_for_job(job_id):
|
try:
|
||||||
notifications = dao_get_all_notifications_for_job(job_id)
|
if all_notifications_are_created_for_job(job_id):
|
||||||
file = ""
|
notifications = dao_get_all_notifications_for_job(job_id)
|
||||||
for n in notifications:
|
file = ""
|
||||||
t = {"content": n.template.content, "subject": n.template.subject}
|
for n in notifications:
|
||||||
# This unique id is a 7 digits requested by DVLA, not known if this number needs to be sequential.
|
t = {"content": n.template.content, "subject": n.template.subject}
|
||||||
unique_id = int(''.join(map(str, random.sample(range(9), 7))))
|
# This unique id is a 7 digits requested by DVLA, not known if this number needs to be sequential.
|
||||||
template = LetterDVLATemplate(t, n.personalisation, unique_id)
|
unique_id = int(''.join(map(str, random.sample(range(9), 7))))
|
||||||
file = file + str(template) + "\n"
|
template = LetterDVLATemplate(t, n.personalisation, unique_id)
|
||||||
s3upload(filedata=file,
|
file = file + str(template) + "\n"
|
||||||
region=current_app.config['AWS_REGION'],
|
s3upload(filedata=file,
|
||||||
bucket_name=current_app.config['DVLA_UPLOAD_BUCKET_NAME'],
|
region=current_app.config['AWS_REGION'],
|
||||||
file_location="{}-dvla-job.text".format(job_id))
|
bucket_name=current_app.config['DVLA_UPLOAD_BUCKET_NAME'],
|
||||||
else:
|
file_location="{}-dvla-job.text".format(job_id))
|
||||||
current_app.logger.info("All notifications for job {} are not persisted".format(job_id))
|
else:
|
||||||
self.retry(queue="retry", exc="All notifications for job {} are not persisted".format(job_id))
|
current_app.logger.info("All notifications for job {} are not persisted".format(job_id))
|
||||||
|
self.retry(queue="retry", exc="All notifications for job {} are not persisted".format(job_id))
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.exception("build_dvla_file threw exception")
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def s3upload(filedata, region, bucket_name, file_location):
|
def s3upload(filedata, region, bucket_name, file_location):
|
||||||
|
|||||||
Reference in New Issue
Block a user