-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathloader.py
37 lines (32 loc) · 1.22 KB
/
loader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from yggdrasil_engine.engine import UnleashEngine
from UnleashClient.cache import BaseCache
from UnleashClient.constants import FEATURES_URL
from UnleashClient.utils import LOGGER
def load_features(
cache: BaseCache,
engine: UnleashEngine,
) -> None:
"""
Caching
:param cache: Should be the cache class variable from UnleashClient
:param feature_toggles: Should be a JSON string containing the feature toggles, equivalent to the response from Unleash API
:return:
"""
# Pull raw provisioning from cache.
feature_provisioning = cache.get(FEATURES_URL)
if not feature_provisioning:
LOGGER.warning(
"Unleash client does not have cached features. "
"Please make sure client can communicate with Unleash server!"
)
return
try:
warnings = engine.take_state(feature_provisioning)
if warnings:
LOGGER.warning(
"Some features were not able to be parsed correctly, they may not evaluate as expected"
)
LOGGER.warning(warnings)
except Exception as e:
LOGGER.error(f"Error loading features: {e}")
LOGGER.debug(f"Full feature response body from server: {feature_provisioning}")