Skip to content

Commit

Permalink
introduce 2 new database connection configs, rename database connecti…
Browse files Browse the repository at this point in the history
…on params
  • Loading branch information
francesconazzaro committed Nov 18, 2024
1 parent 2b74895 commit ad27e8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 6 additions & 4 deletions cads_broker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 7 additions & 5 deletions cads_broker/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ad27e8e

Please sign in to comment.