forked from mtusi2026/mtusi2026lab2
feat-(level 4 completed)
This commit is contained in:
+6
-2
@@ -4,7 +4,7 @@ from sqlalchemy import text
|
||||
|
||||
from src.database import engine, close_engine
|
||||
from src.migrations.runner import run_migrations
|
||||
|
||||
from src.redis_client import init_redis, close_redis
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
@@ -12,6 +12,9 @@ async def lifespan(app: FastAPI):
|
||||
print("lifespan startup: applying migrations...")
|
||||
await run_migrations()
|
||||
|
||||
print("[lifespan] startup: initializing Redis cache...")
|
||||
await init_redis()
|
||||
|
||||
print("lifespan startup: initializing database engine...")
|
||||
async with engine.connect() as conn:
|
||||
await conn.execute(text("SELECT 1"))
|
||||
@@ -19,6 +22,7 @@ async def lifespan(app: FastAPI):
|
||||
|
||||
yield
|
||||
|
||||
print("lifespan shutdown: closing database engine...")
|
||||
print("lifespan shutdown")
|
||||
await close_redis()
|
||||
await close_engine()
|
||||
print("lifespan shutdown: complete")
|
||||
Reference in New Issue
Block a user