Skip to content
Snippets Groups Projects
Verified Commit 04d18fb2 authored by Daniel Göbel's avatar Daniel Göbel
Browse files

Add workflow id to WorkflowExecutionOut scheme

#25
parent c4c14e72
Branches
No related tags found
No related merge requests found
......@@ -131,7 +131,7 @@ async def start_workflow(
slurm_client=slurm_client,
)
return execution
return WorkflowExecutionOut.from_db_model(execution, workflow_id=workflow_version.workflow_id)
@router.post(
......@@ -229,7 +229,7 @@ async def start_arbitrary_workflow(
slurm_client=slurm_client,
)
return execution
return WorkflowExecutionOut.from_db_model(execution)
@router.get("", status_code=status.HTTP_200_OK, summary="Get all workflow executions")
......@@ -283,7 +283,12 @@ async def list_workflow_executions(
executions = await CRUDWorkflowExecution.list(
db, uid=user_id, workflow_version_id=workflow_version_id, status_list=execution_status
)
return executions
return [
WorkflowExecutionOut.from_db_model(
execution, execution.workflow_version.workflow_id if execution.workflow_version is not None else None
)
for execution in executions
]
@router.get("/{eid}", status_code=status.HTTP_200_OK, summary="Get a workflow execution")
......@@ -313,7 +318,10 @@ async def get_workflow_execution(
"""
rbac_operation = "read" if workflow_execution.user_id == current_user.uid else "read_any"
await authorization(rbac_operation)
return workflow_execution
return WorkflowExecutionOut.from_db_model(
workflow_execution,
workflow_execution.workflow_version.workflow_id if workflow_execution.workflow_version is not None else None,
)
@router.delete("/{eid}", status_code=status.HTTP_204_NO_CONTENT, summary="Delete a workflow execution")
......
......@@ -3,6 +3,7 @@ from uuid import UUID
from clowmdb.models import WorkflowExecution
from sqlalchemy import delete, or_, select, update
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import joinedload
from app.schemas.workflow_execution import DevWorkflowExecutionIn, WorkflowExecutionIn
......@@ -68,7 +69,11 @@ class CRUDWorkflowExecution:
The workflow execution with the given id if it exists, None otherwise
"""
eid = execution_id.bytes if isinstance(execution_id, UUID) else execution_id
stmt = select(WorkflowExecution).where(WorkflowExecution._execution_id == eid)
stmt = (
select(WorkflowExecution)
.where(WorkflowExecution._execution_id == eid)
.options(joinedload(WorkflowExecution.workflow_version))
)
execution = (await db.execute(stmt)).scalar()
return execution
......@@ -95,10 +100,10 @@ class CRUDWorkflowExecution:
Returns
-------
workflow_executions : list[clowmdb.models.WorkflowExecution.WorkflowExecutionStatus]
workflow_executions : list[clowmdb.models.WorkflowExecution]
List of all workflow executions with applied filters.
"""
stmt = select(WorkflowExecution)
stmt = select(WorkflowExecution).options(joinedload(WorkflowExecution.workflow_version))
if uid is not None:
stmt = stmt.where(WorkflowExecution.user_id == uid)
if workflow_version_id is not None:
......
......@@ -55,9 +55,21 @@ class WorkflowExecutionOut(_BaseWorkflowExecution):
workflow_version_id: str | None = Field( # type: ignore[assignment]
..., description="Workflow version git commit hash", example="ba8bcd9294c2c96aedefa1763a84a18077c50c0f"
)
workflow_id: UUID | None = Field(
..., description="Id of the workflow", example="0cc78936-381b-4bdd-999d-736c40591078"
)
class Config:
orm_mode = True
@staticmethod
def from_db_model(workflow_execution: WorkflowExecution, workflow_id: UUID | None = None) -> "WorkflowExecutionOut":
return WorkflowExecutionOut(
execution_id=workflow_execution.execution_id,
user_id=workflow_execution.user_id,
start_time=workflow_execution.start_time,
end_time=workflow_execution.end_time,
status=workflow_execution.status,
workflow_version_id=workflow_execution.workflow_version_id,
workflow_id=workflow_id,
)
class DevWorkflowExecutionIn(BaseModel):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment