tea_preview job: one file previewed, result as run output: GET /runs/{id}?outputs=true; the TEA gate also previews one hospital EDF

This commit is contained in:
2026-11-28 13:37:27 -06:00
parent 3438a3135b
commit 70c9506b97
3 changed files with 97 additions and 7 deletions
+17 -6
View File
@@ -1,8 +1,9 @@
"""Runs live in Dagster: the API starts them and reads their state, never computes."""
import json
import os
import time
from typing import Literal
from typing import Any, Literal
import requests
from dagster_graphql import DagsterGraphQLClient, DagsterGraphQLClientError
@@ -29,7 +30,7 @@ STATE: dict[str, State] = {
}
RUN_QUERY = """
query Run($id: ID!) {
query Run($id: ID!, $outputs: Boolean! = false) {
runOrError(runId: $id) {
__typename
... on Run { runId jobName status startTime endTime tags { key value }
@@ -41,6 +42,9 @@ query Run($id: ID!) {
__typename
... on EventConnection { events { __typename
... on MessageEvent { message level stepKey }
... on ExecutionStepOutputEvent @include(if: $outputs) {
stepKey outputName metadataEntries { label ... on JsonMetadataEntry { jsonString } }
}
... on ExecutionStepFailureEvent { error { message causes { message } } }
... on RunFailureEvent { error { message causes { message } } } } }
... on RunNotFoundError { message }
@@ -84,6 +88,7 @@ class Run(RunSummary):
info: list[str]
warnings: list[str]
error: str | None
outputs: dict[str, Any] | None = None
class Cancel(BaseModel):
@@ -159,7 +164,7 @@ def _summary(run: dict) -> RunSummary:
)
def shape(run: dict, logs: list[dict]) -> Run:
def shape(run: dict, logs: list[dict], outputs: bool = False) -> Run:
summary = _summary(run)
progress = None
if (tag := _tags(run).get("isssteleon/progress")) is not None:
@@ -181,6 +186,7 @@ def shape(run: dict, logs: list[dict]) -> Run:
info, warnings = [], []
error = None
result = {} if outputs else None
for event in logs:
kind = event["__typename"]
if kind == "LogMessageEvent" and event["level"] in ("INFO", "WARNING"):
@@ -188,6 +194,10 @@ def shape(run: dict, logs: list[dict]) -> Run:
if step_key := event.get("stepKey"):
line = f"{step_key}: {line}"
(info if event["level"] == "INFO" else warnings).append(line)
if result is not None and kind == "ExecutionStepOutputEvent":
for entry in event.get("metadataEntries", ()):
if "jsonString" in entry:
result[f"{event['stepKey']}.{entry['label']}"] = json.loads(entry["jsonString"])
if summary.state == "failed" and kind in ("ExecutionStepFailureEvent", "RunFailureEvent"):
failure = event.get("error")
error = None
@@ -200,6 +210,7 @@ def shape(run: dict, logs: list[dict]) -> Run:
return Run(
**summary.model_dump(),
progress=progress,
outputs=result,
steps=steps,
info=info[-200:],
warnings=warnings[:200],
@@ -215,11 +226,11 @@ def _result(result: dict, typename: str) -> dict:
@router.get("/{run_id}")
def run_status(run_id: str) -> Run:
data = graphql(RUN_QUERY, {"id": run_id})
def run_status(run_id: str, outputs: bool = False) -> Run:
data = graphql(RUN_QUERY, {"id": run_id, "outputs": outputs})
run = _result(data["runOrError"], "Run")
logs = _result(data["logsForRun"], "EventConnection")
return shape(run, logs["events"])
return shape(run, logs["events"], outputs)
def _status(client: DagsterGraphQLClient, run_id: str) -> str: