Skip to content

Commit 1077116

Browse files
Tomas-PytelTomas-Pytel
authored andcommitted
allow configuration reloading on the fly
1 parent 3a55ea0 commit 1077116

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

fastapi_featureflags/main.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44

55
class FeatureFlags(object):
6+
conf_from_json = None
7+
conf_from_url = None
68
features = {}
79

810
def __init__(
@@ -15,15 +17,22 @@ def __init__(
1517

1618
def handle_config(self, conf_from_json, conf_from_url):
1719
if conf_from_json:
20+
self.conf_from_json = conf_from_json
1821
with open(conf_from_json, "r") as f:
1922
params = json.loads(f.read())
2023
for k, v in params.items():
2124
self.features[k] = v
2225
elif conf_from_url:
26+
self.conf_from_url = conf_from_url
2327
params = requests.get(conf_from_url).json()
24-
print(params)
28+
# print(params)
2529
for k, v in params.items():
2630
self.features[k] = v
31+
return True
32+
33+
def reload_feature_flags(self):
34+
self.handle_config(self.conf_from_json, self.conf_from_url)
35+
return True
2736

2837
@classmethod
2938
def handle_feature(cls, feature_name):

0 commit comments

Comments
 (0)