From d7624c7e0fb9f0a619be314009ee0c05c952c240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o?= Date: Sun, 29 Nov 2026 12:39:00 -0600 Subject: [PATCH] A run can be stopped --- webapi/runs.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/webapi/runs.py b/webapi/runs.py index cc5888e..916cae5 100644 --- a/webapi/runs.py +++ b/webapi/runs.py @@ -21,3 +21,13 @@ def run_status(run_id: str, client: DagsterGraphQLClient = Depends(dagster)) -> return {"id": run_id, "status": client.get_run_status(run_id).value} except DagsterGraphQLClientError as e: raise HTTPException(404 if "RunNotFound" in str(e) else 502, detail=str(e)) from e + + +@router.post("/{run_id}/terminate") +def terminate_run(run_id: str, client: DagsterGraphQLClient = Depends(dagster)) -> dict[str, str]: + """Stop a run (one started by mistake): Dagster cancels it.""" + try: + client.terminate_run(run_id) + return {"id": run_id, "status": client.get_run_status(run_id).value} + except DagsterGraphQLClientError as e: + raise HTTPException(404 if "RunNotFound" in str(e) else 409, detail=str(e)) from e