fix(api): GET /task 内存失后 DB fallback 返 status(治回测 done 后前端轮询 404 死循环卡等待) [nas]
This commit is contained in:
+19
-2
@@ -131,10 +131,27 @@ async def submit_factor(req: FactorAnalysisRequest):
|
||||
@router.get("/task/{task_id}", dependencies=[Depends(verify_token)])
|
||||
def get_status(task_id: str):
|
||||
"""Get task status"""
|
||||
s = get_orchestrator().get_status(task_id)
|
||||
orch = get_orchestrator()
|
||||
s = orch.get_status(task_id)
|
||||
if s is None:
|
||||
# 内存池无此 task(容器重启/已完成被清)→查 DB;有持久化结果则返其 status,
|
||||
# 否则真不存在。治:done task 内存清后 GET /task 404 → 前端轮询死循环卡等待,
|
||||
# 但结果其实在 DB(历史能查)。CTA/组合回测 done 后内存失均受益。
|
||||
try:
|
||||
from sanguo_backtest.result_store import load_result_by_task_id
|
||||
if orch.db_path:
|
||||
r = load_result_by_task_id(task_id, orch.db_path)
|
||||
if r is not None:
|
||||
return {
|
||||
"task_id": task_id,
|
||||
"status": r.status or "done",
|
||||
"stage": "",
|
||||
"error_msg": None,
|
||||
}
|
||||
except Exception:
|
||||
pass
|
||||
raise HTTPException(status_code=404, detail="task not found")
|
||||
pool = get_orchestrator().pool
|
||||
pool = orch.pool
|
||||
stage = pool.get_stage(task_id)
|
||||
task = pool.get_task(task_id)
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user