format code

This commit is contained in:
grillazz 2025-07-29 17:27:56 +02:00
parent 7aace85eeb
commit 060bdb65fe
3 changed files with 13 additions and 5 deletions

View File

@ -20,6 +20,7 @@ from app.services.auth import AuthBearer
logger = AppStructLogger().get_logger() logger = AppStructLogger().get_logger()
templates = Jinja2Templates(directory=Path(__file__).parent.parent / "templates") templates = Jinja2Templates(directory=Path(__file__).parent.parent / "templates")
@asynccontextmanager @asynccontextmanager
async def lifespan(app: FastAPI): async def lifespan(app: FastAPI):
app.redis = await get_redis() app.redis = await get_redis()
@ -30,12 +31,15 @@ async def lifespan(app: FastAPI):
min_size=5, min_size=5,
max_size=20, 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 yield
finally: finally:
await app.redis.close() await app.redis.close()
await app.postgres_pool.close() await app.postgres_pool.close()
def create_app() -> FastAPI: def create_app() -> FastAPI:
app = FastAPI( app = FastAPI(
title="Stuff And Nonsense API", title="Stuff And Nonsense API",
@ -47,7 +51,9 @@ def create_app() -> FastAPI:
app.include_router(shakespeare_router) app.include_router(shakespeare_router)
app.include_router(user_router) app.include_router(user_router)
app.include_router(ml_router, prefix="/v1/ml", tags=["ML"]) 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( app.include_router(
health_router, health_router,
prefix="/v1/health", prefix="/v1/health",
@ -61,6 +67,7 @@ def create_app() -> FastAPI:
return app return app
app = create_app() app = create_app()
# --- Unused/experimental code and TODOs --- # --- Unused/experimental code and TODOs ---

View File

@ -9,6 +9,7 @@ config = ConfigDict(from_attributes=True)
class RandomStuff(BaseModel): class RandomStuff(BaseModel):
chaos: dict[str, Any] = Field(..., description="JSON data for chaos field") chaos: dict[str, Any] = Field(..., description="JSON data for chaos field")
class StuffSchema(BaseModel): class StuffSchema(BaseModel):
name: str = Field( name: str = Field(
title="", title="",

View File

@ -30,7 +30,7 @@ class RotatingBytesLogger:
lineno=0, lineno=0,
msg=message.rstrip("\n"), msg=message.rstrip("\n"),
args=(), args=(),
exc_info=None exc_info=None,
) )
# Check if rotation is needed before emitting # Check if rotation is needed before emitting
@ -78,7 +78,7 @@ class AppStructLogger(metaclass=SingletonMetaNoArgs):
filename=_log_path, filename=_log_path,
maxBytes=10 * 1024 * 1024, # 10MB maxBytes=10 * 1024 * 1024, # 10MB
backupCount=5, backupCount=5,
encoding="utf-8" encoding="utf-8",
) )
structlog.configure( structlog.configure(
cache_logger_on_first_use=True, cache_logger_on_first_use=True,
@ -90,7 +90,7 @@ class AppStructLogger(metaclass=SingletonMetaNoArgs):
structlog.processors.TimeStamper(fmt="iso", utc=True), structlog.processors.TimeStamper(fmt="iso", utc=True),
structlog.processors.JSONRenderer(serializer=orjson.dumps), structlog.processors.JSONRenderer(serializer=orjson.dumps),
], ],
logger_factory=RotatingBytesLoggerFactory(_handler) logger_factory=RotatingBytesLoggerFactory(_handler),
) )
self._logger = structlog.get_logger() self._logger = structlog.get_logger()