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:
parent
7ec987c78d
commit
6b572aa81b
2 changed files with 24 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue