Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define broker db connection parameters in settings #226

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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