diff --git a/app/main.py b/app/main.py index 63a016c..dab1176 100644 --- a/app/main.py +++ b/app/main.py @@ -20,6 +20,7 @@ from app.services.auth import AuthBearer logger = AppStructLogger().get_logger() templates = Jinja2Templates(directory=Path(__file__).parent.parent / "templates") + @asynccontextmanager async def lifespan(app: FastAPI): app.redis = await get_redis() @@ -30,12 +31,15 @@ async def lifespan(app: FastAPI): min_size=5, max_size=20, ) - await logger.ainfo("Postgres pool created", idle_size=app.postgres_pool.get_idle_size()) + await logger.ainfo( + "Postgres pool created", idle_size=app.postgres_pool.get_idle_size() + ) yield finally: await app.redis.close() await app.postgres_pool.close() + def create_app() -> FastAPI: app = FastAPI( title="Stuff And Nonsense API", @@ -47,7 +51,9 @@ def create_app() -> FastAPI: app.include_router(shakespeare_router) app.include_router(user_router) app.include_router(ml_router, prefix="/v1/ml", tags=["ML"]) - app.include_router(health_router, prefix="/v1/public/health", tags=["Health, Public"]) + app.include_router( + health_router, prefix="/v1/public/health", tags=["Health, Public"] + ) app.include_router( health_router, prefix="/v1/health", @@ -61,6 +67,7 @@ def create_app() -> FastAPI: return app + app = create_app() # --- Unused/experimental code and TODOs --- diff --git a/app/schemas/stuff.py b/app/schemas/stuff.py index 994d266..18b3700 100644 --- a/app/schemas/stuff.py +++ b/app/schemas/stuff.py @@ -9,6 +9,7 @@ config = ConfigDict(from_attributes=True) class RandomStuff(BaseModel): chaos: dict[str, Any] = Field(..., description="JSON data for chaos field") + class StuffSchema(BaseModel): name: str = Field( title="", diff --git a/app/utils/logging.py b/app/utils/logging.py index 293efbe..1aece2b 100644 --- a/app/utils/logging.py +++ b/app/utils/logging.py @@ -30,7 +30,7 @@ class RotatingBytesLogger: lineno=0, msg=message.rstrip("\n"), args=(), - exc_info=None + exc_info=None, ) # Check if rotation is needed before emitting @@ -78,7 +78,7 @@ class AppStructLogger(metaclass=SingletonMetaNoArgs): filename=_log_path, maxBytes=10 * 1024 * 1024, # 10MB backupCount=5, - encoding="utf-8" + encoding="utf-8", ) structlog.configure( cache_logger_on_first_use=True, @@ -90,7 +90,7 @@ class AppStructLogger(metaclass=SingletonMetaNoArgs): structlog.processors.TimeStamper(fmt="iso", utc=True), structlog.processors.JSONRenderer(serializer=orjson.dumps), ], - logger_factory=RotatingBytesLoggerFactory(_handler) + logger_factory=RotatingBytesLoggerFactory(_handler), ) self._logger = structlog.get_logger()