From b47d9df26d49c47ea04fc8095b558542e859f6a7 Mon Sep 17 00:00:00 2001 From: Torma Date: Mon, 19 Oct 2020 23:35:41 +0200 Subject: [PATCH] more sessions --- src/resources.py | 49 ++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/resources.py b/src/resources.py index eb3a0a5..29dde91 100644 --- a/src/resources.py +++ b/src/resources.py @@ -35,32 +35,37 @@ class SampleResource(Resource): Post request send to the endpoint :return: """ - if 'file' not in request.files: - return {"err_msg": "no file found"}, 469 - else: - soundfile = request.files['file'] + with start_transaction(op="get-file", name="get-file-from-request"): + if 'file' not in request.files: + return {"err_msg": "no file found"}, 469 + else: + soundfile = request.files['file'] - if 'description' not in request.form: - return {"err_msg": "no description found"}, 470 - else: - description = request.form.get("description") + with start_transaction(op="get-description", name="get-description-from-request"): + if 'description' not in request.form: + return {"err_msg": "no description found"}, 470 + else: + description = request.form.get("description") - if soundfile.content_type != 'audio/wave': - current_app.logger.info( - f"Input file was not WAV.") - return {'err_msg': 'Input file not a wave file.'}, 415 + with start_transaction(op="validate-wave", name="validate-wave-type"): + if soundfile.content_type != 'audio/wave': + current_app.logger.info( + f"Input file was not WAV.") + return {'err_msg': 'Input file not a wave file.'}, 415 - try: - desc = self.sampleschema.loads(description) - except Exception as e: - current_app.logger.exception(e) - return {'err_msg': 'Input JSON schema invalid'}, 417 + with start_transaction(op="validate-description", name="validate-description-schema"): + try: + desc = self.sampleschema.loads(description) + except Exception as e: + current_app.logger.exception(e) + return {'err_msg': 'Input JSON schema invalid'}, 417 - xeger = Xeger(limit=30) - while True: - generated_tag = xeger.xeger(r'^[a-zA-Z]+[0-9a-zA-Z_]*$')[:32] - if len(generated_tag) > 2: # Ensure minimum length - break + with start_transaction(op="tag-generate", name="generate-tag"): + xeger = Xeger(limit=30) + while True: + generated_tag = xeger.xeger(r'^[a-zA-Z]+[0-9a-zA-Z_]*$')[:32] + if len(generated_tag) > 2: # Ensure minimum length + break record = SampleMetadata( device_id=desc['device_id'],