Runs API: a run's state, steps, live progress, info and warnings apart, the failure's own message; cancel; history by job and domain; execution options and health; POST /tea/eegs/analyze

test_runs.py: 17 passed on SQLite and Postgres
(compose test stack). test_conectar.py fails on an identity-merge count, as it does on tea/parity
without this change.
This commit is contained in:
2026-11-28 06:54:00 -06:00
parent 1e878b8942
commit 4793cf01f0
7 changed files with 500 additions and 23 deletions
+16 -13
View File
@@ -4,14 +4,15 @@ scoring runs (Dagster). The API starts runs and reads the registry; it never tra
import mimetypes
from datetime import date
from dagster_graphql import DagsterGraphQLClient, DagsterGraphQLClientError
from dagster_graphql import DagsterGraphQLClient
from fastapi import APIRouter, Depends, HTTPException, UploadFile
from fastapi.responses import Response
from pydantic import BaseModel
from core.domains import Domain
from persistance import registry
from webapi.runs import dagster
from persistance.cluster import Execution
from webapi.runs import dagster, execution_config, submit
router = APIRouter(prefix="/models", tags=["models"])
@@ -76,36 +77,38 @@ def promote(domain: Domain, name: str, version: int) -> dict:
class Training(BaseModel):
as_of: date | None = None # the date the data are taken up to (default: today)
models: list[str] = [] # which (default: all but the slow ones, like CaMa's recurrence)
execution: Execution | None = None
def _submit(client: DagsterGraphQLClient, job: str, op: str, config: dict) -> dict[str, str]:
try:
run_id = client.submit_job_execution(job, run_config={"ops": {op: {"config": config}}})
except DagsterGraphQLClientError as e:
raise HTTPException(502, detail=str(e)) from e
return {"run_id": run_id}
class Analyze(BaseModel):
execution: Execution | None = None
@router.post("/{domain}/train")
def train(domain: Domain, request: Training,
client: DagsterGraphQLClient = Depends(dagster)) -> dict[str, str]: # fmt: skip
"""Starts training a new version of every model of the domain; follow it at /runs."""
config: dict = {"domain": domain.value}
config: dict = {"domain": domain.value, "execution": execution_config(request.execution)}
if request.as_of:
config["as_of"] = request.as_of.isoformat()
if request.models:
config["models"] = request.models
return _submit(client, "train", "train_models", config)
return submit(client, "train", "train_models", config, domain=domain.value)
@router.post("/{domain}/analyze")
def analyze(domain: Domain, client: DagsterGraphQLClient = Depends(dagster)) -> dict[str, str]:
def analyze(
domain: Domain,
request: Analyze = Analyze(), # noqa: B008
client: DagsterGraphQLClient = Depends(dagster),
) -> dict[str, str]:
"""Starts analysing the studies the domain's models read whole (TEA: its EEGs); follow
it at /runs."""
return _submit(client, "analyze", "analyze_studies", {"domain": domain.value})
config = {"domain": domain.value, "execution": execution_config(request.execution)}
return submit(client, "analyze", "analyze_studies", config, domain=domain.value)
@router.post("/{domain}/score")
def score(domain: Domain, client: DagsterGraphQLClient = Depends(dagster)) -> dict[str, str]:
"""Starts a risk batch from each model's champion; follow it at /runs."""
return _submit(client, "score", "score_models", {"domain": domain.value})
return submit(client, "score", "score_models", {"domain": domain.value}, domain=domain.value)