Skip to content

Commit

Permalink
fix: consolidate run details models + None valid out type
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed May 8, 2024
1 parent f4cbd32 commit 702f849
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
12 changes: 6 additions & 6 deletions bento_wes/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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),
Expand All @@ -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):
Expand Down
16 changes: 6 additions & 10 deletions bento_wes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"Run",
"RunWithDetails",
"RunOutput",
"RunWithDetailsAndOutput",
]


Expand Down Expand Up @@ -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]
2 changes: 1 addition & 1 deletion bento_wes/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 702f849

Please sign in to comment.