"""Jobs router — list templates and run jobs.""" from __future__ import annotations from typing import Any from fastapi import APIRouter, Depends, HTTPException from pydantic import BaseModel from dependencies import get_ssh_client from clients.ssh import RemoteSSHClient from jobs import JOB_TEMPLATES, run_job router = APIRouter(prefix="/api/jobs", tags=["jobs"]) class RunJobRequest(BaseModel): job_key: str path: str @router.get("/templates") def get_templates() -> list[dict[str, str]]: """Return available job templates.""" return [ { "key": key, "name": template.name, "description": template.description, } for key, template in JOB_TEMPLATES.items() ] @router.post("/run") def post_run_job( request: RunJobRequest, ssh: RemoteSSHClient = Depends(get_ssh_client), ) -> dict[str, Any]: """Run a job template on a remote path.""" if request.job_key not in JOB_TEMPLATES: raise HTTPException(status_code=400, detail=f"Unknown job key: {request.job_key}") result = run_job(ssh, request.job_key, request.path) return { "job_key": request.job_key, "path": request.path, "exit_status": result.exit_status, "stdout": result.stdout, "stderr": result.stderr, }