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, )