From 9d3ca4d0e2ede8bf5311623baf3fd0c953b84625 Mon Sep 17 00:00:00 2001 From: Stefaan Lippens Date: Tue, 20 Feb 2024 08:47:33 +0100 Subject: [PATCH] Issue #112 move connections_cache_ttl to AggregatorBackendConfig --- src/openeo_aggregator/config.py | 6 +++--- src/openeo_aggregator/connection.py | 2 +- tests/backend_config.py | 1 + tests/conftest.py | 10 +--------- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/openeo_aggregator/config.py b/src/openeo_aggregator/config.py index 0c08022..ba613b8 100644 --- a/src/openeo_aggregator/config.py +++ b/src/openeo_aggregator/config.py @@ -55,9 +55,6 @@ class AggregatorConfig(dict): # See `memoizer_from_config` for details. memoizer = dict_item(default={"type": "dict"}) - # TTL for connection caching. - connections_cache_ttl = dict_item(default=5 * 60.0) - # Just a config field for test purposes (while were stripping down this config class) test_dummy = dict_item(default="alice") @@ -136,6 +133,9 @@ class AggregatorBackendConfig(OpenEoBackendConfig): auth_entitlement_check: Union[bool, dict] = False + # TTL for connection caching. + connections_cache_ttl: float = 5 * 60.0 + # List of collection ids to cover with the aggregator (when None: support union of all upstream collections) collection_whitelist: Optional[List[Union[str, re.Pattern]]] = None diff --git a/src/openeo_aggregator/connection.py b/src/openeo_aggregator/connection.py index c43bbe7..d1393ef 100644 --- a/src/openeo_aggregator/connection.py +++ b/src/openeo_aggregator/connection.py @@ -248,7 +248,7 @@ def from_config(config: AggregatorConfig) -> 'MultiBackendConnection': backends=config.aggregator_backends, configured_oidc_providers=get_backend_config().oidc_providers or config.configured_oidc_providers, memoizer=memoizer_from_config(config, namespace="mbcon"), - connections_cache_ttl=config.connections_cache_ttl, + connections_cache_ttl=get_backend_config().connections_cache_ttl, ) def _get_connections(self, skip_failures=False) -> Iterator[BackendConnection]: diff --git a/tests/backend_config.py b/tests/backend_config.py index e5ed732..2f42ec8 100644 --- a/tests/backend_config.py +++ b/tests/backend_config.py @@ -13,4 +13,5 @@ OidcProvider(id="y-agg", issuer="https://y.test", title="Y (agg)"), OidcProvider(id="z-agg", issuer="https://z.test", title="Z (agg)"), ], + connections_cache_ttl=1.0, ) diff --git a/tests/conftest.py b/tests/conftest.py index 49dcc46..2d0c9d3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -104,14 +104,7 @@ def memoizer_config() -> dict: @pytest.fixture -def connections_cache_ttl() -> float: - """MultiBackendConnection.connections_cache_ttl fixture to allow parameterization""" - return 1.0 - - - -@pytest.fixture -def base_config(configured_oidc_providers, zk_client, memoizer_config, connections_cache_ttl) -> AggregatorConfig: +def base_config(configured_oidc_providers, zk_client, memoizer_config) -> AggregatorConfig: """Base config for tests (without any configured backends).""" conf = AggregatorConfig() conf.config_source = "test fixture base_config" @@ -120,7 +113,6 @@ def base_config(configured_oidc_providers, zk_client, memoizer_config, connectio conf.configured_oidc_providers = configured_oidc_providers conf.memoizer = memoizer_config - conf.connections_cache_ttl = connections_cache_ttl conf.zookeeper_prefix = "/o-a/" conf.partitioned_job_tracking = {