Skip to content

Commit a3b668e

Browse files
authored
Merge pull request #326 from ImMin5/master
Modify delete unified cost logic about not exist workspace
2 parents 4f423f6 + c543942 commit a3b668e

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/spaceone/cost_analysis/service/unified_cost_service.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ def run_unified_cost(self, params: dict) -> None:
138138
workspace_ids = self._get_workspace_ids_with_none(domain_id)
139139

140140
try:
141-
141+
unified_cost_created_at = datetime.now(timezone.utc)
142142
for workspace_id in workspace_ids:
143-
unified_cost_created_at = datetime.now(timezone.utc)
143+
144144
self.create_unified_cost_with_workspace(
145145
exchange_source,
146146
domain_id,
@@ -153,10 +153,10 @@ def run_unified_cost(self, params: dict) -> None:
153153
)
154154
self._delete_old_unified_costs(
155155
domain_id,
156-
workspace_id,
157156
aggregation_month,
158157
is_confirmed,
159158
unified_cost_created_at,
159+
workspace_id,
160160
)
161161

162162
self.unified_cost_job_mgr.update_is_confirmed_unified_cost_job(
@@ -567,15 +567,19 @@ def _get_virtual_workspace_ids_from_ds_account(
567567
def _delete_old_unified_costs(
568568
self,
569569
domain_id: str,
570-
workspace_id: str,
571570
unified_cost_month: str,
572571
is_confirmed: bool,
573572
created_at: datetime,
573+
workspace_id: Union[str, None],
574574
):
575+
query_filter = {"filter": []}
575576

576-
query_filter = {
577-
"filter": [
578-
{"key": "workspace_id", "value": workspace_id, "operator": "eq"},
577+
if workspace_id:
578+
query_filter["filter"].append(
579+
{"key": "workspace_id", "value": workspace_id, "operator": "eq"}
580+
)
581+
query_filter["filter"].extend(
582+
[
579583
{
580584
"key": "billed_year",
581585
"value": unified_cost_month.split("-")[0],
@@ -584,8 +588,8 @@ def _delete_old_unified_costs(
584588
{"key": "billed_month", "value": unified_cost_month, "operator": "eq"},
585589
{"key": "domain_id", "value": domain_id, "operator": "eq"},
586590
{"key": "created_at", "value": created_at, "operator": "lt"},
587-
],
588-
}
591+
]
592+
)
589593

590594
_LOGGER.debug(
591595
f"[delete_old_unified_costs] delete query filter conditions: {query_filter}"

0 commit comments

Comments
 (0)