Skip to content

Commit

Permalink
Enhance logging in timeout decorator of api.py by adding print statem…
Browse files Browse the repository at this point in the history
…ents to track execution start, success, and timeout events. This improves debugging and traceability for asynchronous function calls.
  • Loading branch information
onuratakan committed Jan 7, 2025
1 parent 28959d7 commit bffb2f3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/upsonicai/server/tools/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ def timeout(duration: float):
def decorator(func):
@wraps(func)
async def wrapper(*args, **kwargs):
print(f"Starting execution of {func.__name__} with timeout {duration} seconds")
try:
return await asyncio.wait_for(func(*args, **kwargs), timeout=duration)
result = await asyncio.wait_for(func(*args, **kwargs), timeout=duration)
print(f"Execution of {func.__name__} completed successfully")
return result
except asyncio.TimeoutError:
print(f"Execution of {func.__name__} timed out after {duration} seconds")
raise HTTPException(
status_code=408,
detail=f"Operation timed out after {duration} seconds",
Expand Down

0 comments on commit bffb2f3

Please sign in to comment.