V3.0 优化webui界面
This commit is contained in:
@@ -408,6 +408,38 @@ def create_app(config_path: str) -> FastAPI:
|
||||
}
|
||||
return out
|
||||
|
||||
@app.get("/api/v2/tasks/{task_id}/spec")
|
||||
async def get_task_spec(task_id: str, req: Request) -> Response:
|
||||
"""
|
||||
Returns the TaskSpec YAML for this task.
|
||||
|
||||
Note: We prefer returning a "resolved" TaskSpec (includes default values) so the
|
||||
UI can show a complete spec even if the user submitted a minimal YAML.
|
||||
"""
|
||||
subject = _auth(req)
|
||||
row = db.get_task(task_id)
|
||||
if not row:
|
||||
raise HTTPException(status_code=404, detail="task not found")
|
||||
if not subject.get("is_admin"):
|
||||
if str(row.get("user_id") or "") != str(subject["user_id"]):
|
||||
raise HTTPException(status_code=404, detail="task not found")
|
||||
raw = str(row.get("jobspec_yaml") or "")
|
||||
try:
|
||||
obj = yaml.safe_load(raw) or {}
|
||||
if not isinstance(obj, dict):
|
||||
raise ValueError("jobspec must be a YAML mapping")
|
||||
spec = JobSpec.from_dict(obj)
|
||||
resolved = spec.to_public_dict()
|
||||
attempts = db.list_attempts(task_id)
|
||||
if attempts:
|
||||
resolved["submission_id"] = str(attempts[-1].get("ray_submission_id") or resolved.get("submission_id") or "")
|
||||
text = yaml.safe_dump(resolved, sort_keys=False)
|
||||
except Exception:
|
||||
# Backward compatibility / best-effort: if old rows contain invalid YAML,
|
||||
# fall back to the original content.
|
||||
text = raw
|
||||
return Response(content=text, media_type="text/plain")
|
||||
|
||||
@app.get("/api/v2/tasks/{task_id}/attempts")
|
||||
async def get_attempts(task_id: str, req: Request) -> dict[str, Any]:
|
||||
subject = _auth(req)
|
||||
|
||||
Reference in New Issue
Block a user