Skip to content

Commit

Permalink
define broker db connection settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mcucchi9 committed Nov 20, 2024
1 parent c76f6e6 commit dd8a1d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cads_processing_api_service/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
12 changes: 8 additions & 4 deletions cads_processing_api_service/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import sqlalchemy
import sqlalchemy.orm

from . import config

SETTINGS = config.settings


class ConnectionMode(str, enum.Enum):
"""Database connection mode."""
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit dd8a1d9

Please sign in to comment.