Skip to content

Commit

Permalink
Merge pull request #5 from evo-company/add-dummy-managers
Browse files Browse the repository at this point in the history
add dummy clients
  • Loading branch information
n4mespace authored Jan 23, 2024
2 parents 8298d8a + 53c6c3d commit 1af47e7
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Installation

To install package:

- ``pdm add evo-featureflags-protobuf``
- ``pdm add evo-featureflags-client``

To release package:

Expand Down
4 changes: 3 additions & 1 deletion examples/http/aiohttp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
4 changes: 3 additions & 1 deletion examples/http/httpx_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
2 changes: 2 additions & 0 deletions examples/http/requests_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
73 changes: 73 additions & 0 deletions featureflags_client/http/managers/dummy.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1af47e7

Please sign in to comment.