fix: reliably dispatch and return background tasks
Rebuild & Deploy / rebuild (push) Successful in 47s

This commit is contained in:
snowspeeder committed 2026-08-29 07:29:38 -04:00
1 parent 746ca8dca9
commit 321421e37f
7 files changed
+310 -27

No files matched your search

+7 -1
View File
@@ -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))