"""Runs live in Dagster: the API starts them and reads their state, never computes.""" import os from dagster_graphql import DagsterGraphQLClient, DagsterGraphQLClientError from fastapi import APIRouter, Depends, HTTPException router = APIRouter(prefix="/runs", tags=["runs"]) def dagster() -> DagsterGraphQLClient: return DagsterGraphQLClient( os.environ.get("DAGSTER_HOST", "localhost"), port_number=int(os.environ.get("DAGSTER_PORT", "3000")), ) @router.get("/{run_id}") def run_status(run_id: str, client: DagsterGraphQLClient = Depends(dagster)) -> dict[str, str]: try: 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