Skip to content

Commit

Permalink
add pool timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
extreme4all committed Nov 26, 2023
1 parent 4f77fc5 commit 75d582a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 7 additions & 1 deletion src/core/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
18 changes: 9 additions & 9 deletions src/core/logging_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.*")
File renamed without changes.

0 comments on commit 75d582a

Please sign in to comment.