diff --git a/backend/app/main.py b/backend/app/main.py index e976c02..36fce86 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -11,6 +11,7 @@ import tempfile import threading import uuid +from contextlib import asynccontextmanager from datetime import datetime, timezone from pathlib import Path from typing import List @@ -94,7 +95,17 @@ MAX_UPLOAD_SIZE = MAX_UPLOAD_MB * 1024 * 1024 logger = logging.getLogger(__name__) -app = FastAPI(title="PatchPilot API", version="0.1.0") + + +@asynccontextmanager +async def lifespan(app: FastAPI): + await init_db() + # Start background cleanup for finished ACTIVE_SCANS entries + asyncio.create_task(_cleanup_active_scans_loop()) + yield + + +app = FastAPI(title="PatchPilot API", version="0.1.0", lifespan=lifespan) ALLOWED_ORIGINS = [ "http://localhost:5173", @@ -128,13 +139,6 @@ ensure_dir(WORK_ROOT) -@app.on_event("startup") -async def startup(): - await init_db() - # Start background cleanup for finished ACTIVE_SCANS entries - asyncio.create_task(_cleanup_active_scans_loop()) - - @app.get("/health") def health(): scanners = {