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
|
@app.before_serving
|
||||||
async def startup():
|
async def startup():
|
||||||
|
import asyncio
|
||||||
|
|
||||||
from fabledassistant.services.llm import ensure_model
|
from fabledassistant.services.llm import ensure_model
|
||||||
|
|
||||||
try:
|
async def _pull_model():
|
||||||
await ensure_model(Config.OLLAMA_MODEL)
|
try:
|
||||||
except Exception:
|
await ensure_model(Config.OLLAMA_MODEL)
|
||||||
logger.warning(
|
except Exception:
|
||||||
"Failed to ensure model '%s' on startup — chat may not work until model is available",
|
logger.warning(
|
||||||
Config.OLLAMA_MODEL,
|
"Failed to ensure model '%s' — chat may not work until model is available",
|
||||||
exc_info=True,
|
Config.OLLAMA_MODEL,
|
||||||
)
|
exc_info=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Fire-and-forget so model pull doesn't block startup
|
||||||
|
asyncio.create_task(_pull_model())
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
async def serve_index():
|
async def serve_index():
|
||||||
|
|||||||
Reference in New Issue
Block a user