From 702f849ac217c1f41827534df35ba9431cba063c Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Wed, 8 May 2024 18:29:39 -0400 Subject: [PATCH] fix: consolidate run details models + None valid out type --- bento_wes/db.py | 12 ++++++------ bento_wes/models.py | 16 ++++++---------- bento_wes/runs.py | 2 +- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/bento_wes/db.py b/bento_wes/db.py index 69493b7..c42f9e7 100644 --- a/bento_wes/db.py +++ b/bento_wes/db.py @@ -14,7 +14,7 @@ from .backends.backend_types import Command from .constants import SERVICE_ARTIFACT from .events import get_flask_event_bus -from .models import RunLog, RunRequest, Run, RunWithDetailsAndOutput +from .models import RunLog, RunRequest, Run, RunWithDetails from .types import RunStream from .utils import iso_now @@ -187,13 +187,13 @@ def get_task_logs(c: sqlite3.Cursor, run_id: uuid.UUID | str) -> list: return [task_log_dict(task_log) for task_log in c.fetchall()] @classmethod - def run_with_details_and_output_from_row( + def run_with_details_from_row( cls, c: sqlite3.Cursor, run: sqlite3.Row, stream_content: bool, - ) -> RunWithDetailsAndOutput: - return RunWithDetailsAndOutput.model_validate(dict( + ) -> RunWithDetails: + return RunWithDetails.model_validate(dict( run_id=run["id"], state=run["state"], request=run_request_from_row(run), @@ -218,9 +218,9 @@ def get_run_with_details( c: sqlite3.Cursor, run_id: uuid.UUID | str, stream_content: bool, - ) -> RunWithDetailsAndOutput | None: + ) -> RunWithDetails | None: if run := cls._get_run_row(c, run_id): - return cls.run_with_details_and_output_from_row(c, run, stream_content) + return cls.run_with_details_from_row(c, run, stream_content) return None def set_run_log_name(self, run: Run, workflow_name: str): diff --git a/bento_wes/models.py b/bento_wes/models.py index 572520e..71b0289 100644 --- a/bento_wes/models.py +++ b/bento_wes/models.py @@ -10,7 +10,6 @@ "Run", "RunWithDetails", "RunOutput", - "RunWithDetailsAndOutput", ] @@ -46,16 +45,13 @@ class Run(BaseModel): state: str # TODO: Literal +class RunOutput(BaseModel): # Bento-specific schema + type: str # WDL / (workflow descriptor language) type + value: str | int | float | bool | list | None # Output value + + class RunWithDetails(Run): request: RunRequest run_log: RunLog task_logs: list[dict] # TODO: model - - -class RunOutput(BaseModel): - type: str # WDL / (workflow descriptor language) type - value: str | int | float | bool | list # Output value - - -class RunWithDetailsAndOutput(RunWithDetails): - outputs: dict[str, RunOutput] # Bento-specific extension + outputs: dict[str, RunOutput] diff --git a/bento_wes/runs.py b/bento_wes/runs.py index fa19e60..5a46b56 100644 --- a/bento_wes/runs.py +++ b/bento_wes/runs.py @@ -315,7 +315,7 @@ def run_list(): perms_list: list[RunRequest] = [] for r in c.execute("SELECT * FROM runs").fetchall(): - run = db.run_with_details_and_output_from_row(c, r, stream_content=False) + run = db.run_with_details_from_row(c, r, stream_content=False) perms_list.append(run.request) if not public_endpoint or run.state == STATE_COMPLETE: