fix(replay): preserve failed periodic execution boundaries
Generic Container CI/CD / test-build-publish (push) Successful in 4m23s
Server CI/CD v2 / build-test-publish-and-deploy (push) Successful in 4m23s

This commit is contained in:
2026-11-16 16:21:58 +08:00
parent 389892cb3f
commit 9cd1400723
5 changed files with 119 additions and 11 deletions
+18 -8
View File
@@ -83,19 +83,30 @@ async def enqueue_simulation(repo, context, document, execution) -> None:
)
execution.update(calculation_job_id=str(row["job_id"]), status="pending", summary="等待本周期水力计算。")
except CalculationCapacityExceeded:
execution.update(calculation_job_id=None, status="failed", summary="计算队列已满,水力计算尚未启动,可按原输入重试。")
execution.update(failed_execution(execution, "计算队列已满,水力计算尚未启动,可按原输入重试。"), calculation_job_id=None)
execution["steps"][1].update(status="failed", detail="计算队列容量不足。")
execution["steps"][0].update(status="completed", detail="已冻结本轮模型和周期观测。")
await repo.save_periodic_task(document["replay_id"], execution["batch_sequence"], execution)
await repo.simulation_state(document["replay_id"], execution)
def failed_execution(execution: dict, summary: str) -> dict:
result = {**execution, "status": "failed", "summary": summary,
"steps": [dict(step) for step in execution["steps"]]}
result["steps"][1].update(status="failed", detail=summary)
for step in result["steps"][2:]:
step.update(status="skipped", detail="本周期计算未完成,此步骤尚未执行。")
return result
def project_job(execution: dict, job: dict | None) -> dict:
result = dict(execution)
if execution["status"] in {"completed", "failed"}:
if execution["status"] == "completed":
return result
if execution["status"] == "failed":
return failed_execution(execution, execution["summary"])
if not job:
result.update(status="failed", summary="本周期计算记录不可用,请重试。")
return failed_execution(execution, "本周期计算记录不可用,请重试。")
elif job["status"] in ACTIVE_JOB_STATES:
result.update(status="running" if job["status"] != "queued" else "pending")
result["steps"] = [dict(step) for step in execution["steps"]]
@@ -104,7 +115,7 @@ def project_job(execution: dict, job: dict | None) -> dict:
return PeriodicTaskExecution.model_validate(job["result"]["data"]).model_dump(mode="json")
else:
code = (job.get("error") or {}).get("code", job["status"])
result.update(status="failed", summary=f"本周期水力计算未完成({code}),可按原冻结输入重试。")
return failed_execution(execution, f"本周期水力计算未完成({code}),可按原冻结输入重试。")
return result
@@ -115,7 +126,7 @@ async def project_periodic_tasks(repo, replay_id, offset, limit):
for execution in items:
job = (await queue.get(execution["calculation_job_id"], include_result=True)
if execution.get("calculation_job_id") and execution["status"] not in {"completed", "failed"} else None)
result.append(project_job(execution, job) if execution.get("calculation_job_id") else execution)
result.append(project_job(execution, job))
return result
@@ -239,8 +250,7 @@ async def persist_periodic_terminal(connection, row, terminal):
execution = PeriodicTaskExecution.model_validate(terminal["result"]["data"]).model_dump(mode="json")
else:
code = (terminal.get("error") or {}).get("code", terminal["status"])
execution.update(status="failed", summary=f"本周期水力计算未完成({code}),可按原冻结输入重试。",
updated_at=datetime.now(timezone.utc).isoformat())
execution["steps"][1].update(status="failed", detail=execution["summary"])
execution = failed_execution(execution, f"本周期水力计算未完成({code}),可按原冻结输入重试。")
execution["updated_at"] = datetime.now(timezone.utc).isoformat()
await repo.save_periodic_task(parameters["replay_id"], parameters["batch_sequence"], execution)
await repo.simulation_state(parameters["replay_id"], execution)