Skip to content

Commit 3a9c965

Browse files
committed
Various improvements
- improved RuntimeConfig initialization process (excluded the possibility of side effects) - added the ability to use custom http_client to ConfigServerSrc
1 parent f4e1807 commit 3a9c965

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/runtime_config/runtime_config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
class RuntimeConfig:
2525
def __init__(self, init_settings: SettingsType, source: BaseSource, refresh_interval: float) -> None:
26-
self._init_settings: SettingsType = init_settings
26+
self._init_settings: SettingsType = copy.deepcopy(init_settings)
2727
self._settings: SettingsType = {}
2828

2929
self._source = source
@@ -32,7 +32,9 @@ def __init__(self, init_settings: SettingsType, source: BaseSource, refresh_inte
3232

3333
@staticmethod
3434
async def create(
35-
init_settings: t.Dict[str, t.Any], source: BaseSource | None = None, refresh_interval: float = 10
35+
init_settings: t.Dict[str, t.Any],
36+
source: BaseSource | None = None,
37+
refresh_interval: float = 10,
3638
) -> RuntimeConfig:
3739
"""
3840
Creates and initializes an instance of the class. You should always use this method to instantiate a class.

src/runtime_config/sources/config_server.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@
1515

1616
logger = getLogger(__name__)
1717

18-
SettingsType = t.Dict[str, t.Any]
19-
2018

2119
class ConfigServerSrc(BaseSource):
2220
"""
2321
Source that allows you to get settings from the runtime-config server.
2422
"""
2523

26-
def __init__(self, host: str, service_name: str) -> None:
24+
def __init__(self, host: str, service_name: str, http_client: aiohttp.ClientSession = None) -> None:
2725
self._url = self._build_url(host=host, service_name=service_name)
28-
self._http_client = aiohttp.ClientSession()
26+
self._http_client = http_client or aiohttp.ClientSession()
2927

3028
def _build_url(self, host: str, service_name: str) -> str:
3129
parsed_url = urlparse(host)

0 commit comments

Comments
 (0)