Use connection pool for job enqueueing instead of per-request

- Added get_job_pool() for lazy pool initialization
- Added close_job_pool() for graceful shutdown
- Hooked pool shutdown into FastAPI lifespan
- Reuses connections instead of creating new ones per enqueue
This commit is contained in:
counterweight 2025-12-21 23:13:22 +01:00
parent 7ec987c78d
commit 6b572aa81b
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
2 changed files with 24 additions and 4 deletions

View file

@ -6,6 +6,7 @@ from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from database import Base, engine
from jobs import close_job_pool
from routes import audit as audit_routes
from routes import auth as auth_routes
from routes import availability as availability_routes
@ -27,6 +28,8 @@ async def lifespan(app: FastAPI):
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
yield
# Cleanup on shutdown
await close_job_pool()
app = FastAPI(lifespan=lifespan)