Cleanup of the TEA parity work: no prose in code, no hacks, everything in its place
1. No prose in code - Remove parity-added Python comments and docstrings across the EEG, FHIR, execution, preview, training and run code and tests. Preserve endpoint descriptions as explicit FastAPI schema metadata. 2. No hacks, no glued code - Read the declared TEA patient filters and training inputs directly and use the same TEA check for exposing and validating reference options. - Give the Dagster GraphQL request one helper. Keep lock backoff and cancellation polling because their timing and error behavior are covered by run tests and they handle different Dagster states. - Use the renamed FHIR report ID helper in the hospital test. Keep TEA_GATE_SLOW local to that test and preserve the test assertions. 3. Everything in its place - Keep endpoint and run handling in WebApi and reuse Core and Persistance for domain rules and reads. Leave tests in the existing testpaths.
This commit is contained in:
+17
-16
@@ -106,7 +106,7 @@ def dagster() -> DagsterGraphQLClient:
|
||||
return DagsterGraphQLClient(host, port_number=port)
|
||||
|
||||
|
||||
LOCKED = "database is locked" # Dagster's SQLite run storage, busy while a run writes its events
|
||||
LOCKED = "database is locked"
|
||||
LOCK_RETRIES = 5
|
||||
STARTING_WAIT_S = 30
|
||||
|
||||
@@ -121,24 +121,25 @@ def _locked(payload: dict) -> bool:
|
||||
)
|
||||
|
||||
|
||||
def _graphql_response(url: str, query: str, variables: dict) -> dict:
|
||||
try:
|
||||
response = requests.post(url, json={"query": query, "variables": variables}, timeout=15)
|
||||
if response.status_code != 200:
|
||||
raise HTTPException(502, detail=response.text)
|
||||
return response.json()
|
||||
except requests.RequestException as e:
|
||||
raise HTTPException(502, detail=str(e)) from e
|
||||
|
||||
|
||||
def graphql(query: str, variables: dict) -> dict:
|
||||
"""Dagster's GraphQL answer; a read that found its run storage locked is tried again."""
|
||||
host, port = _dagster_address()
|
||||
for attempt in range(LOCK_RETRIES + 1):
|
||||
try:
|
||||
response = requests.post(
|
||||
f"http://{host}:{port}/graphql",
|
||||
json={"query": query, "variables": variables},
|
||||
timeout=15,
|
||||
)
|
||||
if response.status_code != 200:
|
||||
raise HTTPException(502, detail=response.text)
|
||||
payload = response.json()
|
||||
except requests.RequestException as e:
|
||||
raise HTTPException(502, detail=str(e)) from e
|
||||
if not _locked(payload) or attempt == LOCK_RETRIES:
|
||||
url = f"http://{host}:{port}/graphql"
|
||||
payload = _graphql_response(url, query, variables)
|
||||
for attempt in range(LOCK_RETRIES):
|
||||
if not _locked(payload):
|
||||
break
|
||||
time.sleep(0.2 * 2**attempt)
|
||||
payload = _graphql_response(url, query, variables)
|
||||
if _locked(payload):
|
||||
raise HTTPException(
|
||||
503, detail="Dagster's run storage is busy; try again", headers={"Retry-After": "5"}
|
||||
@@ -244,7 +245,7 @@ def _status(client: DagsterGraphQLClient, run_id: str) -> str:
|
||||
@router.post("/{run_id}/cancel")
|
||||
def cancel_run(run_id: str, client: DagsterGraphQLClient = Depends(dagster)) -> Cancel:
|
||||
status = _status(client, run_id)
|
||||
deadline = time.monotonic() + STARTING_WAIT_S # Dagster cannot terminate a run still starting
|
||||
deadline = time.monotonic() + STARTING_WAIT_S
|
||||
while status == "STARTING" and time.monotonic() < deadline:
|
||||
time.sleep(0.5)
|
||||
status = _status(client, run_id)
|
||||
|
||||
Reference in New Issue
Block a user