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