From a4afbc4846b9d4991a5264077abc5ee1e9dc12ec Mon Sep 17 00:00:00 2001 From: Cino Jose Date: Tue, 12 Sep 2023 13:32:01 +0800 Subject: [PATCH] Add support for SQLAlchemy pool pre ping --- src/dispatch/config.py | 3 +++ src/dispatch/database/core.py | 1 + 2 files changed, 4 insertions(+) diff --git a/src/dispatch/config.py b/src/dispatch/config.py index 78671c06287b..4d5b5eb7674b 100644 --- a/src/dispatch/config.py +++ b/src/dispatch/config.py @@ -203,6 +203,9 @@ def __str__(self) -> str: DATABASE_PORT = config("DATABASE_PORT", default="5432") DATABASE_ENGINE_POOL_SIZE = config("DATABASE_ENGINE_POOL_SIZE", cast=int, default=20) DATABASE_ENGINE_MAX_OVERFLOW = config("DATABASE_ENGINE_MAX_OVERFLOW", cast=int, default=0) +# Deal with DB disconnects +# https://docs.sqlalchemy.org/en/20/core/pooling.html#pool-disconnects +DATABASE_ENGINE_POOL_PING = config("DATABASE_ENGINE_POOL_PING", default=False) SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{_DATABASE_CREDENTIAL_USER}:{_QUOTED_DATABASE_PASSWORD}@{DATABASE_HOSTNAME}:{DATABASE_PORT}/{DATABASE_NAME}" ALEMBIC_CORE_REVISION_PATH = config( diff --git a/src/dispatch/database/core.py b/src/dispatch/database/core.py index f12fe2cb74de..4410aa2ed789 100644 --- a/src/dispatch/database/core.py +++ b/src/dispatch/database/core.py @@ -20,6 +20,7 @@ config.SQLALCHEMY_DATABASE_URI, pool_size=config.DATABASE_ENGINE_POOL_SIZE, max_overflow=config.DATABASE_ENGINE_MAX_OVERFLOW, + pool_pre_ping=config.DATABASE_ENGINE_POOL_PING, )