result.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import json
  2. import uuid
  3. from flask import Blueprint
  4. from db.task import Task
  5. from route.util import make_response
  6. bp = Blueprint("result", __name__, url_prefix='/')
  7. @bp.route("/result/<task_uuid>", methods=["GET"])
  8. def get_result(task_uuid):
  9. try:
  10. uuid.UUID(task_uuid, version=4)
  11. except:
  12. return make_response(400, "invalid uuid format", {})
  13. task = Task.query.get(task_uuid)
  14. status = task.status
  15. if status == 'FINISHED':
  16. return make_response(200, "success",
  17. {"task_uuid": task.uuid, "type": task.type, "status": "FINISHED", "result": json.loads(task.result)})
  18. elif status == 'QUEUEING':
  19. return make_response(200, "success", {"task_uuid": task.uuid, "type": task.type, "status": "QUEUEING"})
  20. elif status == 'RUNNING':
  21. return make_response(200, "success", {"task_uuid": task.uuid, "type": task.type, "status": "RUNNING", "progress": task.progress})
  22. elif status == 'ERROR':
  23. return make_response(200, "success", {"task_uuid": task.uuid, "type": task.type, "status": "ERROR"})
  24. else:
  25. assert 0.1 + 0.2 == 0.3, "what do u mean?"