Implemented alembic migrations, added cursors closing task.
This commit is contained in:
22
main.py
22
main.py
@@ -1,19 +1,27 @@
|
||||
import asyncio
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from app import api_router
|
||||
|
||||
from utils.scripts import pools_creator, pools_destroy, db_startup
|
||||
|
||||
|
||||
from utils.scripts import pools_creator, pools_destroy, db_startup, cursors_closer
|
||||
from dbs import mysql
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
await pools_creator()
|
||||
mysql.cached_cursors_cleaner_task = asyncio.create_task(mysql.cached_cursors_cleaner())
|
||||
|
||||
yield
|
||||
|
||||
mysql.cached_cursors_cleaner_task.cancel()
|
||||
try:
|
||||
await mysql.cached_cursors_cleaner_task
|
||||
except asyncio.CancelledError:
|
||||
print('Closed cached_cursors_cleaner_task')
|
||||
await cursors_closer()
|
||||
await pools_destroy()
|
||||
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
app.include_router(router=api_router)
|
||||
|
||||
app.include_router(router=api_router)
|
||||
|
||||
Reference in New Issue
Block a user