44"""Workflow API routes with tenant-scoped access control."""
55
66import asyncio
7+ import logging
78from typing import Any
89
910from fastapi import APIRouter , Depends , HTTPException , Request
2021from app .workflows .registry import get_workflow_spec
2122from app .workflows .specs import WorkflowContext
2223
24+ logger = logging .getLogger (__name__ )
25+
2326router = APIRouter (
2427 prefix = "/workflows" ,
2528 tags = ["workflows" ],
@@ -108,8 +111,8 @@ async def create(
108111 session .add (workflow )
109112 session .commit ()
110113 workflow_id = workflow .public_id
111- except SQLAlchemyError as e :
112- print ("Error(create)" , e )
114+ except SQLAlchemyError :
115+ logger . exception ("Error creating workflow" )
113116 raise HTTPException (status_code = 500 , detail = "Could not create workflow" )
114117
115118 try :
@@ -126,8 +129,8 @@ async def create(
126129 id = f"{ spec .id_prefix } -{ workflow_id } " ,
127130 task_queue = spec .task_queue ,
128131 )
129- except Exception as e :
130- print ("Error(start_temporal_workflow)" , e )
132+ except Exception :
133+ logger . exception ("Error starting Temporal workflow" )
131134 try :
132135 workflow .status = WorkflowStatus .ERROR
133136 session .commit ()
@@ -153,8 +156,8 @@ async def read(
153156 workflow = session .exec (
154157 select (Workflow ).where (Workflow .public_id == workflow_id )
155158 ).one ()
156- except SQLAlchemyError as e :
157- print ("Error(read)" , e )
159+ except SQLAlchemyError :
160+ logger . exception ("Error reading workflow" )
158161 raise HTTPException (status_code = 404 , detail = "Workflow not found" )
159162
160163 verify_tenant_owns_workflow (auth , workflow )
@@ -178,8 +181,8 @@ async def workflow_event(request: Request, workflow_id: str):
178181
179182 if status == "ERROR" or status == "SUCCESS" :
180183 break
181- except SQLAlchemyError as e :
182- print ("Error(stream)" , e )
184+ except SQLAlchemyError :
185+ logger . exception ("Error streaming workflow status" )
183186 raise HTTPException (status_code = 500 )
184187
185188 await asyncio .sleep (STREAM_DELAY )
0 commit comments