From dd8a1d96fbead9a246c58da0622fe402dac2ec10 Mon Sep 17 00:00:00 2001 From: Marco Cucchi Date: Wed, 20 Nov 2024 12:13:21 +0100 Subject: [PATCH] define broker db connection settings --- cads_processing_api_service/config.py | 5 +++++ cads_processing_api_service/db_utils.py | 12 ++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cads_processing_api_service/config.py b/cads_processing_api_service/config.py index 4b0414b..25e6359 100644 --- a/cads_processing_api_service/config.py +++ b/cads_processing_api_service/config.py @@ -197,6 +197,11 @@ def profiles_api_url(self) -> str: missing_licences_message: str = MISSING_LICENCES_MESSAGE dataset_licences_url: str = DATASET_LICENCES_URL + retrieve_api_broker_pool_timeout: float = 1.0 + retrieve_api_broker_pool_recycle: int = 60 + retrieve_api_broker_pool_size: int = 5 + retrieve_api_broker_max_overflow: int = 15 + rate_limits_file: str | None = None rate_limits: RateLimitsConfig = pydantic.Field(default=RateLimitsConfig()) diff --git a/cads_processing_api_service/db_utils.py b/cads_processing_api_service/db_utils.py index 799bc20..d50d854 100644 --- a/cads_processing_api_service/db_utils.py +++ b/cads_processing_api_service/db_utils.py @@ -22,6 +22,10 @@ import sqlalchemy import sqlalchemy.orm +from . import config + +SETTINGS = config.settings + class ConnectionMode(str, enum.Enum): """Database connection mode.""" @@ -56,10 +60,10 @@ def get_compute_sessionmaker( raise ValueError(f"Invalid connection mode: {str(mode)}") broker_engine = sqlalchemy.create_engine( connection_string, - pool_timeout=broker_settings.broker_pool_timeout, - pool_recycle=broker_settings.broker_pool_recycle, - pool_size=broker_settings.broker_pool_size, - max_overflow=broker_settings.broker_max_overflow, + pool_timeout=SETTINGS.retrieve_api_broker_pool_timeout, + pool_recycle=SETTINGS.retrieve_api_broker_pool_recycle, + pool_size=SETTINGS.retrieve_api_broker_pool_size, + max_overflow=SETTINGS.retrieve_api_broker_max_overflow, ) return sqlalchemy.orm.sessionmaker(broker_engine)