diff options
Diffstat (limited to 'app/main.py')
| -rw-r--r-- | app/main.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/app/main.py b/app/main.py index f1c556a..49e7a1f 100644 --- a/app/main.py +++ b/app/main.py @@ -1,15 +1,20 @@ import time from contextlib import asynccontextmanager +from pathlib import Path +from dotenv import load_dotenv from fastapi import FastAPI from sqlalchemy import text from app.routes import router as api_router from app.utils.cors import setup_cors from app.utils.create_tables import init_db -from app.utils.db import engine +from app.utils.db import get_engine, init_db_engine from app.utils.logger_cfg import logger +load_dotenv(Path(__file__).resolve().parent.parent / ".env") +init_db_engine() + app_start_time = time.perf_counter() logger.debug("App start timestamp recorded") @@ -18,6 +23,8 @@ logger.debug("App start timestamp recorded") async def lifespan(app: FastAPI): logger.info("Application startup initiated") + engine = get_engine() + try: async with engine.begin() as conn: logger.debug("Executing test query: SELECT 1") @@ -46,6 +53,7 @@ async def lifespan(app: FastAPI): logger.info("Application shutdown initiated") try: + engine = get_engine() await engine.dispose() logger.info("Database engine disposed successfully") except Exception: |
