From 61e322b774e46e1a69edc7fedf9274e121adf00d Mon Sep 17 00:00:00 2001 From: Jongmin Kim Date: Mon, 22 Jan 2024 22:13:04 +0900 Subject: [PATCH] fix: fix budget alarm --- .../cost_analysis/manager/budget_usage_manager.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/spaceone/cost_analysis/manager/budget_usage_manager.py b/src/spaceone/cost_analysis/manager/budget_usage_manager.py index e0ea7551..ffda5acc 100644 --- a/src/spaceone/cost_analysis/manager/budget_usage_manager.py +++ b/src/spaceone/cost_analysis/manager/budget_usage_manager.py @@ -117,7 +117,7 @@ def notify_budget_usage(self, budget_vo: Budget): notification_type = notification.notification_type is_notify = False - if budget_vo.time_unit == "MONTHLY": + if budget_vo.time_unit == "TOTAL": budget_usage_vos = self.filter_budget_usages( budget_id=budget_id, workspace_id=workspace_id, @@ -134,6 +134,13 @@ def notify_budget_usage(self, budget_vo: Budget): domain_id=domain_id, date=current_month, ) + + if budget_usage_vos.count() == 0: + _LOGGER.debug( + f"[notify_budget_usage] budget_usage_vos is empty: {budget_id}" + ) + continue + total_budget_usage = budget_usage_vos[0].cost budget_limit = budget_usage_vos[0].limit