From 53c6c3d31bb0e96170e9d339ee466e47f4885e1a Mon Sep 17 00:00:00 2001 From: "d.zakharchuk" Date: Tue, 23 Jan 2024 14:54:15 +0200 Subject: [PATCH] add dummy clients --- README.md | 2 +- examples/http/aiohttp_client.py | 4 +- examples/http/httpx_client.py | 4 +- examples/http/requests_client.py | 2 + featureflags_client/http/managers/dummy.py | 73 ++++++++++++++++++++++ pdm.lock | 2 +- 6 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 featureflags_client/http/managers/dummy.py diff --git a/README.md b/README.md index b6a4115..42fed52 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Installation To install package: -- ``pdm add evo-featureflags-protobuf`` +- ``pdm add evo-featureflags-client`` To release package: diff --git a/examples/http/aiohttp_client.py b/examples/http/aiohttp_client.py index 6f57f8e..f5b5d86 100644 --- a/examples/http/aiohttp_client.py +++ b/examples/http/aiohttp_client.py @@ -16,11 +16,13 @@ async def on_start(app): project=config.FF_PROJECT, variables=[flags.REQUEST_QUERY], defaults=flags.Defaults, + request_timeout=5, + refresh_interval=10, ) app["ff_client"] = FeatureFlagsClient(app["ff_manager"]) try: - await app["ff_client"].preload_async(timeout=5) + await app["ff_client"].preload_async() except Exception: log.exception( "Unable to preload feature flags, application will " diff --git a/examples/http/httpx_client.py b/examples/http/httpx_client.py index 5df7c33..7782ace 100644 --- a/examples/http/httpx_client.py +++ b/examples/http/httpx_client.py @@ -16,11 +16,13 @@ async def on_start(app): project=config.FF_PROJECT, variables=[flags.REQUEST_QUERY], defaults=flags.Defaults, + request_timeout=5, + refresh_interval=10, ) app["ff_client"] = FeatureFlagsClient(app["ff_manager"]) try: - await app["ff_client"].preload_async(timeout=5) + await app["ff_client"].preload_async() except Exception: log.exception( "Unable to preload feature flags, application will " diff --git a/examples/http/requests_client.py b/examples/http/requests_client.py index eb3e625..b15a914 100644 --- a/examples/http/requests_client.py +++ b/examples/http/requests_client.py @@ -19,6 +19,8 @@ def get_ff_client(): project=config.FF_PROJECT, variables=[flags.REQUEST_QUERY], defaults=flags.Defaults, + request_timeout=5, + refresh_interval=10, ) ff_client = g._ff_client = FeatureFlagsClient(manager) return ff_client diff --git a/featureflags_client/http/managers/dummy.py b/featureflags_client/http/managers/dummy.py new file mode 100644 index 0000000..b3ceefc --- /dev/null +++ b/featureflags_client/http/managers/dummy.py @@ -0,0 +1,73 @@ +import logging +from typing import Any, Callable, Dict, Optional + +from featureflags_client.http.constants import Endpoints +from featureflags_client.http.managers.base import ( + AsyncBaseManager, + BaseManager, +) + +log = logging.getLogger(__name__) + + +class DummyManager(BaseManager): + """Dummy feature flags manager. + + It can be helpful when you want to use flags with their default values. + """ + + def get(self, name: str) -> Optional[Callable[[Dict], bool]]: + """ + So that `featureflags.http.flags.Flags` will use default values. + """ + return None + + def sync(self) -> None: + pass + + def preload(self) -> None: + pass + + def _post( + self, + url: Endpoints, + payload: Dict[str, Any], + timeout: int, + ) -> Dict[str, Any]: + pass + + +class AsyncDummyManager(AsyncBaseManager): + """Dummy feature flags manager for asyncio apps. + + It can be helpful when you want to use flags with their default values. + """ + + def get(self, name: str) -> Optional[Callable[[Dict], bool]]: + """ + So that `featureflags.http.flags.Flags` will use default values. + """ + return None + + async def _post( # type: ignore + self, + url: Endpoints, + payload: Dict[str, Any], + timeout: int, + ) -> Dict[str, Any]: + pass + + async def close(self) -> None: + pass + + async def sync(self) -> None: # type: ignore + pass + + async def preload(self) -> None: # type: ignore + pass + + def start(self) -> None: + pass + + async def wait_closed(self) -> None: + pass diff --git a/pdm.lock b/pdm.lock index 69bb036..8d52130 100644 --- a/pdm.lock +++ b/pdm.lock @@ -2,7 +2,7 @@ # It is not intended for manual editing. [metadata] -groups = ["default", "dev", "docs", "examples", "lint", "test", "aiohttp", "requests", "ptpython"] +groups = ["default", "dev", "docs", "examples", "lint", "test", "aiohttp", "requests"] strategy = ["cross_platform", "inherit_metadata"] lock_version = "4.4.1" content_hash = "sha256:c7bbb6cf01030ad7838b479d4786a3836b5c8e5e1c146cfcd53743604cbc0a0b"