fix: reliably dispatch and return background tasks
Rebuild & Deploy / rebuild (push) Successful in 47s
Rebuild & Deploy / rebuild (push) Successful in 47s
This commit is contained in:
1 parent
746ca8dca9
commit
321421e37f
7 files changed
+310
-27
No files matched your search
@@ -11,6 +11,7 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
|
||||
@@ -51,8 +52,13 @@ async def _run_worker(worker: "TaskWorker", task_id: str):
|
||||
except ImportError:
|
||||
from task_registry import registry
|
||||
|
||||
timeout_seconds = float(os.environ.get("TASK_TIMEOUT_SECONDS", "180"))
|
||||
try:
|
||||
await worker.run()
|
||||
await asyncio.wait_for(worker.run(), timeout=timeout_seconds)
|
||||
except asyncio.TimeoutError:
|
||||
message = f"Timed out after {timeout_seconds:g} seconds"
|
||||
logger.error("Task %s %s", task_id, message.lower())
|
||||
registry.fail(task_id, message)
|
||||
except Exception as e:
|
||||
logger.exception("Task %s crashed: %s", task_id, e)
|
||||
registry.fail(task_id, str(e))
|
||||
|
||||
Reference in new issue
Block a user