From 75d582af9ce876adf194183c6dbf94d70c140a80 Mon Sep 17 00:00:00 2001 From: extreme4all <> Date: Sun, 26 Nov 2023 21:15:10 +0100 Subject: [PATCH] add pool timeout --- src/core/config.py | 4 ++-- src/core/database/database.py | 8 +++++++- src/core/logging_config.py | 18 +++++++++--------- {src/tests => tests}/.gitkeep | 0 4 files changed, 18 insertions(+), 12 deletions(-) rename {src/tests => tests}/.gitkeep (100%) diff --git a/src/core/config.py b/src/core/config.py index 9c6a1da..d3dc92c 100644 --- a/src/core/config.py +++ b/src/core/config.py @@ -5,7 +5,7 @@ class Settings(BaseSettings): ENV: str DATABASE_URL: str KAFKA_HOST: str - POOL_RECYCLE: int - POOL_TIMEOUT: int + POOL_RECYCLE: int = 25 + POOL_TIMEOUT: int = 25 settings = Settings() \ No newline at end of file diff --git a/src/core/database/database.py b/src/core/database/database.py index 92a90f6..07b7d54 100644 --- a/src/core/database/database.py +++ b/src/core/database/database.py @@ -6,7 +6,13 @@ from src.core.config import settings # Create an async SQLAlchemy engine -engine = create_async_engine(settings.DATABASE_URL, echo=(settings.ENV != "PRD"),pool_pre_ping=True,) +engine = create_async_engine( + settings.DATABASE_URL, + pool_timeout=settings.POOL_TIMEOUT, + pool_recycle=settings.POOL_RECYCLE, + echo=(settings.ENV != "PRD"), + pool_pre_ping=True, +) # Create a session factory SessionFactory = sessionmaker( diff --git a/src/core/logging_config.py b/src/core/logging_config.py index 6eaf651..d9918b7 100644 --- a/src/core/logging_config.py +++ b/src/core/logging_config.py @@ -32,12 +32,12 @@ logging.getLogger("aiomysql").setLevel(logging.ERROR) logging.getLogger("aiokafka").setLevel(logging.WARNING) -if settings.ENV == "PRD": - uvicorn_error = logging.getLogger("uvicorn.error") - uvicorn_error.disabled = True - uvicorn_access = logging.getLogger("uvicorn.access") - uvicorn_access.disabled = True - -# https://github.com/aio-libs/aiomysql/issues/103 -# https://github.com/coleifer/peewee/issues/2229 -warnings.filterwarnings("ignore", ".*Duplicate entry.*") +# if settings.ENV == "PRD": +# uvicorn_error = logging.getLogger("uvicorn.error") +# uvicorn_error.disabled = True +# uvicorn_access = logging.getLogger("uvicorn.access") +# uvicorn_access.disabled = True + +# # https://github.com/aio-libs/aiomysql/issues/103 +# # https://github.com/coleifer/peewee/issues/2229 +# warnings.filterwarnings("ignore", ".*Duplicate entry.*") diff --git a/src/tests/.gitkeep b/tests/.gitkeep similarity index 100% rename from src/tests/.gitkeep rename to tests/.gitkeep