Skip to content

Commit 8ef4097

Browse files
authored
Merge pull request #41 from hellohaptik/BB-7914
Return empty response from Feature Toggles Library if redis is down
2 parents 44930f0 + 38dbf03 commit 8ef4097

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

FeatureToggle/__init__.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ def is_enabled_for_domain(feature_name: str,
153153
(bool): True if Feature is enabled else False
154154
"""
155155
feature_toggles = FeatureToggles.fetch_feature_toggles()
156-
LOGGER.info(f"Enable_for_domain_FT_cache_info: {FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
156+
LOGGER.info(f"Enable_for_domain_FT_cache_info: "
157+
f"{FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
157158
return domain_name in feature_toggles.get(feature_name, {}).get('domain_names', [])
158159

159160
@staticmethod
@@ -168,7 +169,8 @@ def is_enabled_for_partner(feature_name: str,
168169
(bool): True if Feature is enabled else False
169170
"""
170171
feature_toggles = FeatureToggles.fetch_feature_toggles()
171-
LOGGER.info(f"Enable_for_partner_FT_cache_info: {FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
172+
LOGGER.info(f"Enable_for_partner_FT_cache_info: "
173+
f"{FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
172174
return partner_name in feature_toggles.get(feature_name, {}).get('partner_names', [])
173175

174176
@staticmethod
@@ -183,7 +185,8 @@ def is_enabled_for_business(feature_name: str,
183185
(bool): True if Feature is enabled else False
184186
"""
185187
feature_toggles = FeatureToggles.fetch_feature_toggles()
186-
LOGGER.info(f"Enable_for_business_FT_cache_info: {FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
188+
LOGGER.info(f"Enable_for_business_FT_cache_info: "
189+
f"{FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
187190
return business_via_name in feature_toggles.get(feature_name, {}).get('business_via_names', [])
188191

189192
@staticmethod
@@ -198,7 +201,8 @@ def is_enabled_for_expert(feature_name: str,
198201
(bool): True if Feature is enabled else False
199202
"""
200203
feature_toggles = FeatureToggles.fetch_feature_toggles()
201-
LOGGER.info(f"Enable_for_expert_FT_cache_info: {FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
204+
LOGGER.info(f"Enable_for_expert_FT_cache_info: "
205+
f"{FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
202206
return expert_email in feature_toggles.get(feature_name, {}).get('expert_emails', [])
203207

204208
@staticmethod
@@ -213,7 +217,8 @@ def is_enabled_for_team(feature_name: str,
213217
(bool): True if feature is enabled else False
214218
"""
215219
feature_toggles = FeatureToggles.fetch_feature_toggles()
216-
LOGGER.info(f"Enable_for_team_FT_cache_info: {FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
220+
LOGGER.info(f"Enable_for_team_FT_cache_info: "
221+
f"{FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
217222
return team_id in feature_toggles.get(feature_name, {}).get('team_ids', [])
218223

219224
@staticmethod
@@ -231,19 +236,18 @@ def fetch_feature_toggles():
231236
}
232237
"""
233238
# TODO: Remove the cas and environment name from the feature toggles while returning the response
239+
response = {}
234240
LOGGER.info(f'Loading Feature Toggles from Redis')
235-
LOGGER.info(f"Efetch_feature_toggles_cache_info: {FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
241+
LOGGER.info(f"Fetch_feature_toggles_cache_info:"
242+
f"{FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
236243
if FeatureToggles.__cache is None:
237-
raise Exception(
238-
'To update cache Feature Toggles class needs to be initialised'
239-
)
240-
241-
feature_toggles = pickle.loads(
242-
FeatureToggles.__cache.get(consts.FEATURES_URL)
243-
)
244-
response = {}
244+
LOGGER.error('To update cache Feature Toggles class needs to be initialised')
245+
return response
245246

246247
try:
248+
feature_toggles = pickle.loads(
249+
FeatureToggles.__cache.get(consts.FEATURES_URL)
250+
)
247251
if feature_toggles:
248252
for feature_toggle in feature_toggles:
249253
full_feature_name = feature_toggle['name']
@@ -291,5 +295,5 @@ def fetch_feature_toggles():
291295
response[full_feature_name]['team_ids'] = team_ids
292296
except Exception as err:
293297
# Handle this exception from where this util gets called
294-
raise Exception(f'An error occurred while parsing the response: {str(err)}')
298+
LOGGER.error(f'An error occurred while parsing the response: {str(err)}')
295299
return response

0 commit comments

Comments
 (0)