diff --git a/wwwroot/api/fix_stuck.dspy b/wwwroot/api/fix_stuck.dspy new file mode 100644 index 0000000..ec46a6f --- /dev/null +++ b/wwwroot/api/fix_stuck.dspy @@ -0,0 +1,26 @@ +# fix_stuck.dspy - 清除卡住任务的 claimed_by + +dbname = get_module_dbname('pipeline-sdlc') +async with DBPools().sqlorContext(dbname) as sor: + # 清除 submitted 状态但有 claimed_by 的僵尸任务 + result = await sor.sqlExe( + "UPDATE pipeline_tasks SET claimed_by=NULL WHERE state='submitted' AND claimed_by IS NOT NULL", + {}) + # 同时清除 review 状态但有 claimed_by 的(超时未处理的) + result2 = await sor.sqlExe( + "UPDATE pipeline_tasks SET claimed_by=NULL WHERE state='review' AND claimed_by IS NOT NULL", + {}) + + # 查看还有多少卡住的 + stuck = await sor.sqlExe( + "SELECT id, title, role, state, claimed_by FROM pipeline_tasks WHERE claimed_by IS NOT NULL", + {}) + +result = { + "cleared_submitted": "done", + "cleared_review": "done", + "remaining_stuck": [{"id": getattr(t,'id','')[:12], "state": getattr(t,'state',''), + "claimed_by": getattr(t,'claimed_by','')[:8]} for t in (stuck or [])] +} + +return json.dumps(result, ensure_ascii=False)