MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / api_start_selfcheck_run

Function api_start_selfcheck_run

src/web/routes/selfcheck.py:236–306  ·  view source on GitHub ↗
(request: StartSelfCheckRequest)

Source from the content-addressed store, hash-verified

234
235@router.post("/runs")
236def api_start_selfcheck_run(request: StartSelfCheckRequest):
237 mode = _normalize_mode(request.mode)
238 source = str(request.source or "manual").strip().lower() or "manual"
239
240 if has_running_selfcheck_run():
241 running = _build_running_run_payload()
242 raise HTTPException(
243 status_code=409,
244 detail={
245 "message": "已有运行中的自检任务,请稍后再试",
246 "running_run": running,
247 },
248 )
249
250 if request.run_async:
251 latest = _start_selfcheck_background(mode, source)
252 return {
253 "success": True,
254 "message": "自检任务已创建并开始执行",
255 "run": latest,
256 }
257
258 run = create_selfcheck_run(mode=mode, source=source)
259 run_id = int(run["id"])
260 task_id = _selfcheck_task_id(run_id)
261 task_manager.register_domain_task(
262 domain="selfcheck",
263 task_id=task_id,
264 task_type="selfcheck_run",
265 payload={"run_id": run_id, "mode": mode, "source": source},
266 progress={"completed": 0, "total": 0},
267 max_retries=3,
268 )
269 acquired, running, quota = task_manager.try_acquire_domain_slot("selfcheck", task_id)
270 if not acquired:
271 reason = f"并发配额已满(running={running}, quota={quota})"
272 task_manager.update_domain_task(
273 "selfcheck",
274 task_id,
275 status="failed",
276 finished_at=datetime.utcnow().isoformat(),
277 message=reason,
278 error=reason,
279 )
280 raise HTTPException(status_code=429, detail=reason)
281 try:
282 result = execute_selfcheck_run(
283 run_id,
284 mode=mode,
285 source=source,
286 cancel_checker=lambda: task_manager.is_domain_task_cancel_requested("selfcheck", task_id),
287 )
288 status_text = str(result.get("status") or "").strip().lower()
289 mapped_status = status_text if status_text in {"completed", "failed", "cancelled"} else "completed"
290 task_manager.update_domain_task(
291 "selfcheck",
292 task_id,
293 status=mapped_status,

Callers

nothing calls this directly

Calls 13

create_selfcheck_runFunction · 0.85
_selfcheck_task_idFunction · 0.85
execute_selfcheck_runFunction · 0.85
register_domain_taskMethod · 0.80
update_domain_taskMethod · 0.80
release_domain_slotMethod · 0.80
_normalize_modeFunction · 0.70

Tested by

no test coverage detected