Delete main.py
Browse files
main.py
DELETED
|
@@ -1,45 +0,0 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
-
from fastapi.staticfiles import StaticFiles
|
| 4 |
-
from contextlib import asynccontextmanager
|
| 5 |
-
import asyncio
|
| 6 |
-
from api.routes import router
|
| 7 |
-
from api.routers.auth import router as auth_router
|
| 8 |
-
from api.dependencies import patient_service
|
| 9 |
-
|
| 10 |
-
async def session_sweeper_task():
|
| 11 |
-
"""Background task to sweep idle sessions every 5 minutes."""
|
| 12 |
-
while True:
|
| 13 |
-
try:
|
| 14 |
-
# Sweep sessions inactive for 30 minutes
|
| 15 |
-
patient_service.sweep_abandoned_sessions(timeout_minutes=30)
|
| 16 |
-
except Exception as e:
|
| 17 |
-
print(f"[Sweeper Error] {e}")
|
| 18 |
-
# Sleep for 5 minutes
|
| 19 |
-
await asyncio.sleep(300)
|
| 20 |
-
|
| 21 |
-
@asynccontextmanager
|
| 22 |
-
async def lifespan(app: FastAPI):
|
| 23 |
-
# Startup: Start the background sweeper
|
| 24 |
-
sweeper = asyncio.create_task(session_sweeper_task())
|
| 25 |
-
yield
|
| 26 |
-
# Shutdown: Cancel the task
|
| 27 |
-
sweeper.cancel()
|
| 28 |
-
try:
|
| 29 |
-
await sweeper
|
| 30 |
-
except asyncio.CancelledError:
|
| 31 |
-
pass
|
| 32 |
-
|
| 33 |
-
app = FastAPI(title="Serinity", version="2.0.0", lifespan=lifespan)
|
| 34 |
-
|
| 35 |
-
app.add_middleware(
|
| 36 |
-
CORSMiddleware,
|
| 37 |
-
allow_origins=["*"],
|
| 38 |
-
allow_methods=["*"],
|
| 39 |
-
allow_headers=["*"],
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
-
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 43 |
-
|
| 44 |
-
app.include_router(auth_router)
|
| 45 |
-
app.include_router(router)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|