From a0ec8af7c97908cfc52f7513770319fad641bd3a Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Fri, 17 Mar 2017 16:25:27 +0000 Subject: [PATCH 1/3] Added logging for any exception thrown in build_dvla_file --- app/celery/tasks.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/app/celery/tasks.py b/app/celery/tasks.py index fc50e4e0c..6a8e61caf 100644 --- a/app/celery/tasks.py +++ b/app/celery/tasks.py @@ -265,22 +265,25 @@ def persist_letter( @notify_celery.task(bind=True, name="build-dvla-file", max_retries=15, default_retry_delay=300) @statsd(namespace="tasks") def build_dvla_file(self, job_id): - if all_notifications_are_created_for_job(job_id): - notifications = dao_get_all_notifications_for_job(job_id) - file = "" - for n in notifications: - t = {"content": n.template.content, "subject": n.template.subject} - # This unique id is a 7 digits requested by DVLA, not known if this number needs to be sequential. - unique_id = int(''.join(map(str, random.sample(range(9), 7)))) - template = LetterDVLATemplate(t, n.personalisation, unique_id) - file = file + str(template) + "\n" - s3upload(filedata=file, - region=current_app.config['AWS_REGION'], - bucket_name=current_app.config['DVLA_UPLOAD_BUCKET_NAME'], - file_location="{}-dvla-job.text".format(job_id)) - else: - 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)) + try: + if all_notifications_are_created_for_job(job_id): + notifications = dao_get_all_notifications_for_job(job_id) + file = "" + for n in notifications: + t = {"content": n.template.content, "subject": n.template.subject} + # This unique id is a 7 digits requested by DVLA, not known if this number needs to be sequential. + unique_id = int(''.join(map(str, random.sample(range(9), 7)))) + template = LetterDVLATemplate(t, n.personalisation, unique_id) + file = file + str(template) + "\n" + s3upload(filedata=file, + region=current_app.config['AWS_REGION'], + bucket_name=current_app.config['DVLA_UPLOAD_BUCKET_NAME'], + file_location="{}-dvla-job.text".format(job_id)) + else: + 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: {}", e) def s3upload(filedata, region, bucket_name, file_location): From d83144732908028b77853e460191849847da4272 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Fri, 17 Mar 2017 16:33:51 +0000 Subject: [PATCH 2/3] re-raise execption --- app/celery/tasks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/celery/tasks.py b/app/celery/tasks.py index 6a8e61caf..0abda053a 100644 --- a/app/celery/tasks.py +++ b/app/celery/tasks.py @@ -284,6 +284,7 @@ def build_dvla_file(self, 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: {}", e) + raise e def s3upload(filedata, region, bucket_name, file_location): From 8225a57d508443fa2f0d50810149340fa72da888 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Fri, 17 Mar 2017 16:57:00 +0000 Subject: [PATCH 3/3] reformat execption --- app/celery/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/celery/tasks.py b/app/celery/tasks.py index 0abda053a..c4ea9731f 100644 --- a/app/celery/tasks.py +++ b/app/celery/tasks.py @@ -283,7 +283,7 @@ def build_dvla_file(self, 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: {}", e) + current_app.logger.exception("build_dvla_file threw exception") raise e