feat: 启动时检查数据库连接

This commit is contained in:
martsforever
2026-04-01 14:31:59 +08:00
parent fa4cf72aff
commit 9a663619ca
2 changed files with 66 additions and 0 deletions
+3
View File
@@ -15,13 +15,16 @@ from app.controller.add_graph_proxy_route import add_graph_proxy_route
from app.routes import routes
from app.utils.get_local_ips import get_local_ips
from app.utils.llm_utils import create_llm
from app.utils.mysql_utils import check_database_connection
@asynccontextmanager
async def lifespan(app: FastAPI):
print(f"应用启动:{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
async_engine = await check_database_connection()
yield
print(f"应用销毁:{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
await async_engine.dispose()
app = FastAPI(