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

Update catalogue session instantiation #228

Merged
merged 1 commit into from
Dec 2, 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 @@ -202,6 +202,11 @@ def profiles_api_url(self) -> str:
retrieve_api_broker_pool_size: int = 5
retrieve_api_broker_max_overflow: int = 15

retrieve_api_catalogue_pool_timeout: float = 0.1
retrieve_api_catalogue_pool_recycle: int = 60
retrieve_api_catalogue_pool_size: int = 5
retrieve_api_catalogue_max_overflow: int = 15

rate_limits_file: str | None = None
rate_limits: RateLimitsConfig = pydantic.Field(default=RateLimitsConfig())

Expand Down
21 changes: 11 additions & 10 deletions cads_processing_api_service/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,17 @@ def get_catalogue_sessionmaker(
sqlalchemy.orm.sessionmaker
sqlalchemy.orm.sessionmaker object bound to the Catalogue database.
"""
catalogue_settings = cads_catalogue.config.ensure_settings()
if mode == ConnectionMode.write:
connection_string = catalogue_settings.connection_string
elif mode == ConnectionMode.read:
connection_string = catalogue_settings.connection_string_read
if mode == ConnectionMode.read:
read_only = True
elif mode == ConnectionMode.write:
read_only = False
else:
raise ValueError(f"Invalid connection mode: {str(mode)}")
catalogue_engine = sqlalchemy.create_engine(
connection_string,
pool_timeout=0.1,
pool_recycle=catalogue_settings.pool_recycle,
catalogue_session = cads_catalogue.database.ensure_session_obj(
read_only=read_only,
pool_timeout=SETTINGS.retrieve_api_catalogue_pool_timeout,
pool_recycle=SETTINGS.retrieve_api_catalogue_pool_recycle,
pool_size=SETTINGS.retrieve_api_catalogue_pool_size,
max_overflow=SETTINGS.retrieve_api_catalogue_max_overflow,
)
return sqlalchemy.orm.sessionmaker(catalogue_engine)
return catalogue_session