Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dummy clients #5

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.