Refactorizing function to reduce its Cognitive Complexity
This commit is contained in:
@@ -449,11 +449,8 @@ class SlotManager(SientiaMonitoring):
|
|||||||
alert_type in receiver_group['contents']
|
alert_type in receiver_group['contents']
|
||||||
and notification_id not in ignore_list
|
and notification_id not in ignore_list
|
||||||
and key not in already_added_keys
|
and key not in already_added_keys
|
||||||
and (not levels_list or notification.get('level') in levels_list)
|
and self._check_levels_and_ignore_models_id(
|
||||||
and (
|
notification, levels_list, ignore_models_id_list)
|
||||||
not ignore_models_id_list
|
|
||||||
or notification.get('model_id') not in ignore_models_id_list
|
|
||||||
)
|
|
||||||
):
|
):
|
||||||
receiver_groups[group_name]['notifications'].append(notification)
|
receiver_groups[group_name]['notifications'].append(notification)
|
||||||
already_added_keys.append(key)
|
already_added_keys.append(key)
|
||||||
@@ -467,6 +464,23 @@ class SlotManager(SientiaMonitoring):
|
|||||||
|
|
||||||
return receiver_groups
|
return receiver_groups
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _check_levels_and_ignore_models_id(notification, levels_list, ignore_models_id_list):
|
||||||
|
"""
|
||||||
|
Check if the notification's level is in the levels_list and its model_id is not in the ignore_models_id_list.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
notification (dict): The notification to check.
|
||||||
|
levels_list (list, optional): List of levels to include. If None, all levels are included.
|
||||||
|
ignore_models_id_list (list, optional): List of model_ids to exclude. If None, no models are excluded.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: True if the notification passes the checks, False otherwise.
|
||||||
|
"""
|
||||||
|
level_check = not levels_list or notification.get('level') in levels_list
|
||||||
|
model_id_check = not ignore_models_id_list or notification.get('model_id') not in ignore_models_id_list
|
||||||
|
return level_check and model_id_check
|
||||||
|
|
||||||
@activity.defn(name='store_notification_cache')
|
@activity.defn(name='store_notification_cache')
|
||||||
def store_notification_cache(self, input_data: dict[str, Any]) -> None:
|
def store_notification_cache(self, input_data: dict[str, Any]) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user