INNER CODE UNIT · Python
cancel_run
tomascupr/sandstorm · src/sandstorm/main.py:484
async def cancel_run(run_id: str, token: str = Depends(verify_api_token)):
run = run_store.get(run_id)
if run is None:
return JSONResponse({"error": "unknown run_id"}, status_code=404)
if run.status != "running":
return JSONResponse(
{"error": f"run status is {run.status}, cannot cancel"}, status_code=409
)
if cancellation.request_cancellation(run_id):
return {"status": "cancelling", "run_id": run_id}
# Run has a "running" status in the store but no active event: fail the
# record so the operator isn't stuck with a zombie.
run_store.fail(run_id, "cancelled (stale registration)")
return JSONResponse({"error": "run had no active cancellation event"}, status_code=409)