Run model pull as background task to avoid startup timeout
ensure_model() can take minutes to pull a multi-GB model, which exceeds Hypercorn's startup timeout. Now fires as an asyncio background task so the app starts immediately. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -24,16 +24,22 @@ def create_app() -> Quart:
|
||||
|
||||
@app.before_serving
|
||||
async def startup():
|
||||
import asyncio
|
||||
|
||||
from fabledassistant.services.llm import ensure_model
|
||||
|
||||
try:
|
||||
await ensure_model(Config.OLLAMA_MODEL)
|
||||
except Exception:
|
||||
logger.warning(
|
||||
"Failed to ensure model '%s' on startup — chat may not work until model is available",
|
||||
Config.OLLAMA_MODEL,
|
||||
exc_info=True,
|
||||
)
|
||||
async def _pull_model():
|
||||
try:
|
||||
await ensure_model(Config.OLLAMA_MODEL)
|
||||
except Exception:
|
||||
logger.warning(
|
||||
"Failed to ensure model '%s' — chat may not work until model is available",
|
||||
Config.OLLAMA_MODEL,
|
||||
exc_info=True,
|
||||
)
|
||||
|
||||
# Fire-and-forget so model pull doesn't block startup
|
||||
asyncio.create_task(_pull_model())
|
||||
|
||||
@app.route("/")
|
||||
async def serve_index():
|
||||
|
||||
Reference in New Issue
Block a user