Skip to content

Commit 38dbf03

Browse files
Return empty response from Feature Toggles Library if redis is down
1 parent b8bc556 commit 38dbf03

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
@@ -148,7 +148,8 @@ def is_enabled_for_domain(feature_name: str,
148148
(bool): True if Feature is enabled else False
149149
"""
150150
feature_toggles = FeatureToggles.fetch_feature_toggles()
151-
LOGGER.info(f"Enable_for_domain_FT_cache_info: {FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
151+
LOGGER.info(f"Enable_for_domain_FT_cache_info: "
152+
f"{FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
152153
return domain_name in feature_toggles.get(feature_name, {}).get('domain_names', [])
153154

154155
@staticmethod
@@ -163,7 +164,8 @@ def is_enabled_for_partner(feature_name: str,
163164
(bool): True if Feature is enabled else False
164165
"""
165166
feature_toggles = FeatureToggles.fetch_feature_toggles()
166-
LOGGER.info(f"Enable_for_partner_FT_cache_info: {FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
167+
LOGGER.info(f"Enable_for_partner_FT_cache_info: "
168+
f"{FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
167169
return partner_name in feature_toggles.get(feature_name, {}).get('partner_names', [])
168170

169171
@staticmethod
@@ -178,7 +180,8 @@ def is_enabled_for_business(feature_name: str,
178180
(bool): True if Feature is enabled else False
179181
"""
180182
feature_toggles = FeatureToggles.fetch_feature_toggles()
181-
LOGGER.info(f"Enable_for_business_FT_cache_info: {FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
183+
LOGGER.info(f"Enable_for_business_FT_cache_info: "
184+
f"{FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
182185
return business_via_name in feature_toggles.get(feature_name, {}).get('business_via_names', [])
183186

184187
@staticmethod
@@ -193,7 +196,8 @@ def is_enabled_for_expert(feature_name: str,
193196
(bool): True if Feature is enabled else False
194197
"""
195198
feature_toggles = FeatureToggles.fetch_feature_toggles()
196-
LOGGER.info(f"Enable_for_expert_FT_cache_info: {FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
199+
LOGGER.info(f"Enable_for_expert_FT_cache_info: "
200+
f"{FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
197201
return expert_email in feature_toggles.get(feature_name, {}).get('expert_emails', [])
198202

199203
@staticmethod
@@ -208,7 +212,8 @@ def is_enabled_for_team(feature_name: str,
208212
(bool): True if feature is enabled else False
209213
"""
210214
feature_toggles = FeatureToggles.fetch_feature_toggles()
211-
LOGGER.info(f"Enable_for_team_FT_cache_info: {FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
215+
LOGGER.info(f"Enable_for_team_FT_cache_info: "
216+
f"{FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
212217
return team_id in feature_toggles.get(feature_name, {}).get('team_ids', [])
213218

214219
@staticmethod
@@ -226,19 +231,18 @@ def fetch_feature_toggles():
226231
}
227232
"""
228233
# TODO: Remove the cas and environment name from the feature toggles while returning the response
234+
response = {}
229235
LOGGER.info(f'Loading Feature Toggles from Redis')
230-
LOGGER.info(f"Efetch_feature_toggles_cache_info: {FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
236+
LOGGER.info(f"Fetch_feature_toggles_cache_info:"
237+
f"{FeatureToggles.fetch_feature_toggles.__wrapped__.cache_info()}")
231238
if FeatureToggles.__cache is None:
232-
raise Exception(
233-
'To update cache Feature Toggles class needs to be initialised'
234-
)
235-
236-
feature_toggles = pickle.loads(
237-
FeatureToggles.__cache.get(consts.FEATURES_URL)
238-
)
239-
response = {}
239+
LOGGER.error('To update cache Feature Toggles class needs to be initialised')
240+
return response
240241

241242
try:
243+
feature_toggles = pickle.loads(
244+
FeatureToggles.__cache.get(consts.FEATURES_URL)
245+
)
242246
if feature_toggles:
243247
for feature_toggle in feature_toggles:
244248
full_feature_name = feature_toggle['name']
@@ -286,5 +290,5 @@ def fetch_feature_toggles():
286290
response[full_feature_name]['team_ids'] = team_ids
287291
except Exception as err:
288292
# Handle this exception from where this util gets called
289-
raise Exception(f'An error occurred while parsing the response: {str(err)}')
293+
LOGGER.error(f'An error occurred while parsing the response: {str(err)}')
290294
return response

0 commit comments

Comments
 (0)