feat: stabilize workflow phase 1 foundation
This commit is contained in:
@@ -28,6 +28,7 @@ from app.domains.rendering.schemas import (
|
||||
WorkflowDefinitionOut,
|
||||
WorkflowRunOut,
|
||||
)
|
||||
from app.domains.rendering.workflow_config_utils import canonicalize_workflow_config
|
||||
from app.domains.rendering.workflow_schema import WorkflowConfig
|
||||
from app.core.process_steps import StepName
|
||||
|
||||
@@ -90,6 +91,17 @@ class PipelineStepsResponse(BaseModel):
|
||||
router = APIRouter(prefix="/api/workflows", tags=["workflows"])
|
||||
|
||||
|
||||
def _workflow_to_out(wf: WorkflowDefinition) -> WorkflowDefinitionOut:
|
||||
return WorkflowDefinitionOut(
|
||||
id=wf.id,
|
||||
name=wf.name,
|
||||
output_type_id=wf.output_type_id,
|
||||
config=canonicalize_workflow_config(wf.config),
|
||||
is_active=wf.is_active,
|
||||
created_at=wf.created_at,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/pipeline-steps", response_model=PipelineStepsResponse)
|
||||
async def get_pipeline_steps(
|
||||
_user: User = Depends(require_admin_or_pm),
|
||||
@@ -115,7 +127,7 @@ async def list_workflows(
|
||||
result = await db.execute(
|
||||
select(WorkflowDefinition).order_by(WorkflowDefinition.created_at)
|
||||
)
|
||||
return result.scalars().all()
|
||||
return [_workflow_to_out(wf) for wf in result.scalars().all()]
|
||||
|
||||
|
||||
@router.get("/{workflow_id}", response_model=WorkflowDefinitionOut)
|
||||
@@ -130,7 +142,7 @@ async def get_workflow(
|
||||
wf = result.scalar_one_or_none()
|
||||
if not wf:
|
||||
raise HTTPException(status_code=404, detail="Workflow definition not found")
|
||||
return wf
|
||||
return _workflow_to_out(wf)
|
||||
|
||||
|
||||
@router.post("", response_model=WorkflowDefinitionOut, status_code=201)
|
||||
@@ -139,21 +151,23 @@ async def create_workflow(
|
||||
_user: User = Depends(require_global_admin),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
normalized_config = canonicalize_workflow_config(body.config)
|
||||
if body.config:
|
||||
try:
|
||||
WorkflowConfig.model_validate(body.config)
|
||||
except ValidationError as exc:
|
||||
raise HTTPException(status_code=422, detail=f"Invalid workflow config: {exc.errors()}")
|
||||
WorkflowConfig.model_validate(normalized_config)
|
||||
except (ValidationError, ValueError) as exc:
|
||||
detail = exc.errors() if isinstance(exc, ValidationError) else str(exc)
|
||||
raise HTTPException(status_code=422, detail=f"Invalid workflow config: {detail}")
|
||||
wf = WorkflowDefinition(
|
||||
name=body.name,
|
||||
output_type_id=body.output_type_id,
|
||||
config=body.config,
|
||||
config=normalized_config,
|
||||
is_active=body.is_active,
|
||||
)
|
||||
db.add(wf)
|
||||
await db.commit()
|
||||
await db.refresh(wf)
|
||||
return wf
|
||||
return _workflow_to_out(wf)
|
||||
|
||||
|
||||
@router.put("/{workflow_id}", response_model=WorkflowDefinitionOut)
|
||||
@@ -174,16 +188,18 @@ async def update_workflow(
|
||||
wf.name = body.name
|
||||
if body.config is not None:
|
||||
try:
|
||||
WorkflowConfig.model_validate(body.config)
|
||||
except ValidationError as exc:
|
||||
raise HTTPException(status_code=422, detail=f"Invalid workflow config: {exc.errors()}")
|
||||
wf.config = body.config
|
||||
normalized_config = canonicalize_workflow_config(body.config)
|
||||
WorkflowConfig.model_validate(normalized_config)
|
||||
except (ValidationError, ValueError) as exc:
|
||||
detail = exc.errors() if isinstance(exc, ValidationError) else str(exc)
|
||||
raise HTTPException(status_code=422, detail=f"Invalid workflow config: {detail}")
|
||||
wf.config = normalized_config
|
||||
if body.is_active is not None:
|
||||
wf.is_active = body.is_active
|
||||
|
||||
await db.commit()
|
||||
await db.refresh(wf)
|
||||
return wf
|
||||
return _workflow_to_out(wf)
|
||||
|
||||
|
||||
@router.delete("/{workflow_id}", status_code=204)
|
||||
|
||||
Reference in New Issue
Block a user