From 95eb6edf900d2fcf20b232e73d84a282af0bc50e Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 20 Dec 2024 22:29:33 -0500 Subject: [PATCH] Enhance DESDResource result status handling: allow for PENDING status, add new result status if none exists, and ensure proper database commits. --- app/resources/desd/desd_resource.py | 31 ++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/app/resources/desd/desd_resource.py b/app/resources/desd/desd_resource.py index 0d775b5..7b09f4b 100644 --- a/app/resources/desd/desd_resource.py +++ b/app/resources/desd/desd_resource.py @@ -36,14 +36,27 @@ def post(self): if result: result_status = ResultStatus.query.filter_by(result_id=result.id).first() - if result_status.status in [ResultStatusEnum.RUNNING]: - return {"message": f"The result has status {result_status.status}"}, 400 - - if result_status.status == ResultStatusEnum.COMPLETED: - result_status.models = ','.join(model_names) - result_status.status = ResultStatusEnum.PENDING - result_status.created_at = db.func.now() - result_status.last_updated_at = db.func.now() + if result_status: + + if result_status.status in [ResultStatusEnum.RUNNING, ResultStatusEnum.PENDING]: + return {"message": f"The result has status {result_status.status}"}, 400 + + if result_status.status == ResultStatusEnum.COMPLETED: + result_status.models = ','.join(model_names) + result_status.status = ResultStatusEnum.PENDING + result_status.created_at = db.func.now() + result_status.last_updated_at = db.func.now() + db.session.commit() + else: + result_status = ResultStatus( + result_id=result.id, + status=ResultStatusEnum.PENDING, + total_files=len(files), + total_files_processed=0, + models=','.join(model_names), + last_updated_at=db.func.now() + ) + db.session.add(result_status) db.session.commit() else: result = Result( @@ -60,7 +73,7 @@ def post(self): status=ResultStatusEnum.PENDING, total_files=len(files), total_files_processed=0, - model_names=','.join(model_names), + models=','.join(model_names), last_updated_at=db.func.now() ) db.session.add(result_status)