@@ -138,9 +138,9 @@ def run_unified_cost(self, params: dict) -> None:
138
138
workspace_ids = self ._get_workspace_ids_with_none (domain_id )
139
139
140
140
try :
141
-
141
+ unified_cost_created_at = datetime . now ( timezone . utc )
142
142
for workspace_id in workspace_ids :
143
- unified_cost_created_at = datetime . now ( timezone . utc )
143
+
144
144
self .create_unified_cost_with_workspace (
145
145
exchange_source ,
146
146
domain_id ,
@@ -153,10 +153,10 @@ def run_unified_cost(self, params: dict) -> None:
153
153
)
154
154
self ._delete_old_unified_costs (
155
155
domain_id ,
156
- workspace_id ,
157
156
aggregation_month ,
158
157
is_confirmed ,
159
158
unified_cost_created_at ,
159
+ workspace_id ,
160
160
)
161
161
162
162
self .unified_cost_job_mgr .update_is_confirmed_unified_cost_job (
@@ -567,15 +567,19 @@ def _get_virtual_workspace_ids_from_ds_account(
567
567
def _delete_old_unified_costs (
568
568
self ,
569
569
domain_id : str ,
570
- workspace_id : str ,
571
570
unified_cost_month : str ,
572
571
is_confirmed : bool ,
573
572
created_at : datetime ,
573
+ workspace_id : Union [str , None ],
574
574
):
575
+ query_filter = {"filter" : []}
575
576
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
+ [
579
583
{
580
584
"key" : "billed_year" ,
581
585
"value" : unified_cost_month .split ("-" )[0 ],
@@ -584,8 +588,8 @@ def _delete_old_unified_costs(
584
588
{"key" : "billed_month" , "value" : unified_cost_month , "operator" : "eq" },
585
589
{"key" : "domain_id" , "value" : domain_id , "operator" : "eq" },
586
590
{"key" : "created_at" , "value" : created_at , "operator" : "lt" },
587
- ],
588
- }
591
+ ]
592
+ )
589
593
590
594
_LOGGER .debug (
591
595
f"[delete_old_unified_costs] delete query filter conditions: { query_filter } "
0 commit comments