Skip to content

Commit

Permalink
update catalogue session instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
mcucchi9 committed Nov 26, 2024
1 parent fe3f0bf commit 6ed9dd7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 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 @@ -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

0 comments on commit 6ed9dd7

Please sign in to comment.