import json import uuid from flask import Blueprint from db.task import Task from route.util import make_response bp = Blueprint("result", __name__, url_prefix='/') @bp.route("/result/", methods=["GET"]) def get_result(task_uuid): try: uuid.UUID(task_uuid, version=4) except: return make_response(400, "invalid uuid format", {}) task = Task.query.get(task_uuid) status = task.status if status == 'FINISHED': return make_response(200, "success", {"task_uuid": task.uuid, "type": task.type, "status": "FINISHED", "result": json.loads(task.result)}) elif status == 'QUEUEING': return make_response(200, "success", {"task_uuid": task.uuid, "type": task.type, "status": "QUEUEING"}) elif status == 'RUNNING': return make_response(200, "success", {"task_uuid": task.uuid, "type": task.type, "status": "RUNNING", "progress": task.progress}) elif status == 'ERROR': return make_response(200, "success", {"task_uuid": task.uuid, "type": task.type, "status": "ERROR"}) else: assert 0.1 + 0.2 == 0.3, "what do u mean?"