From ad27e8e4a8004d6ee6b31ef1a417371d44f52296 Mon Sep 17 00:00:00 2001 From: Francesco Nazzaro Date: Mon, 18 Nov 2024 13:21:20 +0100 Subject: [PATCH] introduce 2 new database connection configs, rename database connection params --- cads_broker/config.py | 10 ++++++---- cads_broker/database.py | 12 +++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/cads_broker/config.py b/cads_broker/config.py index 73c71562..b9320ae6 100644 --- a/cads_broker/config.py +++ b/cads_broker/config.py @@ -57,10 +57,12 @@ class SqlalchemySettings(pydantic_settings.BaseSettings): compute_db_host: str | None = None compute_db_host_read: str | None = None compute_db_name: str | None = None - pool_timeout: float = 1.0 - pool_recycle: int = 60 - pool_size: int = 5 - max_overflow: int = 15 + broker_pool_timeout: float = 1.0 + broker_pool_recycle: int = 60 + broker_pool_size: int = 5 + broker_max_overflow: int = 15 + broker_pool_pre_ping: bool = False + broker_pool_use_lifo: bool = False @pydantic.field_validator( "compute_db_user", diff --git a/cads_broker/database.py b/cads_broker/database.py index 2c9aef82..4bea5213 100644 --- a/cads_broker/database.py +++ b/cads_broker/database.py @@ -196,15 +196,17 @@ def ensure_session_obj( connection_string = settings.connection_string_read elif mode == "w": connection_string = settings.connection_string - if settings.pool_size == -1: + if settings.broker_pool_size == -1: engine = sa.create_engine(connection_string, poolclass=sa.pool.NullPool) else: engine = sa.create_engine( connection_string, - pool_recycle=settings.pool_recycle, - pool_size=settings.pool_size, - pool_timeout=settings.pool_timeout, - max_overflow=settings.max_overflow, + pool_recycle=settings.broker_pool_recycle, + pool_size=settings.broker_pool_size, + pool_timeout=settings.broker_pool_timeout, + max_overflow=settings.broker_max_overflow, + pool_pre_ping=settings.broker_pool_pre_ping, + pool_use_lifo=settings.broker_pool_use_lifo, ) session_obj = sa.orm.sessionmaker(engine) return session_obj