Update statsd decorator so that it will log on error.

Added logging for the build_dvla_file task
This commit is contained in:
Rebecca Law
2017-03-17 12:38:24 +00:00
parent d090451dd8
commit f01760f6e6
2 changed files with 26 additions and 13 deletions

View File

@@ -83,6 +83,8 @@ def process_job(job_id):
) )
if template.template_type == LETTER_TYPE: if template.template_type == LETTER_TYPE:
build_dvla_file.apply_async([str(job.id)], queue='process-job') build_dvla_file.apply_async([str(job.id)], queue='process-job')
# temporary logging
current_app.logger.info("send job {} to build-dvla-file in the process-job queue".format(job_id))
def process_row(row_number, recipient, personalisation, template, job, service): def process_row(row_number, recipient, personalisation, template, job, service):
@@ -277,6 +279,7 @@ def build_dvla_file(self, job_id):
bucket_name=current_app.config['DVLA_UPLOAD_BUCKET_NAME'], bucket_name=current_app.config['DVLA_UPLOAD_BUCKET_NAME'],
file_location="{}-dvla-job.text".format(job_id)) file_location="{}-dvla-job.text".format(job_id))
else: 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)) self.retry(queue="retry", exc="All notifications for job {} are not persisted".format(job_id))

View File

@@ -10,20 +10,30 @@ def statsd(namespace):
@functools.wraps(func) @functools.wraps(func)
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
start_time = monotonic() start_time = monotonic()
res = func(*args, **kwargs) try:
elapsed_time = monotonic() - start_time res = func(*args, **kwargs)
current_app.logger.info( elapsed_time = monotonic() - start_time
"{namespace} call {func} took {time}".format(
namespace=namespace, func=func.__name__, time="{0:.4f}".format(elapsed_time) except Exception as e:
current_app.logger.error(
"{namespace} call {func} failed".format(
namespace=namespace, func=func.__name__
)
) )
) raise e
statsd_client.incr('{namespace}.{func}'.format( else:
namespace=namespace, func=func.__name__) current_app.logger.info(
) "{namespace} call {func} took {time}".format(
statsd_client.timing('{namespace}.{func}'.format( namespace=namespace, func=func.__name__, time="{0:.4f}".format(elapsed_time)
namespace=namespace, func=func.__name__), elapsed_time )
) )
return res statsd_client.incr('{namespace}.{func}'.format(
namespace=namespace, func=func.__name__)
)
statsd_client.timing('{namespace}.{func}'.format(
namespace=namespace, func=func.__name__), elapsed_time
)
return res
wrapper.__wrapped__.__name__ = func.__name__ wrapper.__wrapped__.__name__ = func.__name__
return wrapper return wrapper