Skip to content

Commit

Permalink
Enhance DESDResource result status handling: allow for PENDING status…
Browse files Browse the repository at this point in the history
…, add new result status if none exists, and ensure proper database commits.
  • Loading branch information
Erik172 committed Dec 21, 2024
1 parent 508402b commit 95eb6ed
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions app/resources/desd/desd_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down

0 comments on commit 95eb6ed

Please sign in to comment.