@@ -78,7 +78,7 @@ def run_unified_cost_by_scheduler(self, params: dict) -> None:
78
78
79
79
except Exception as e :
80
80
_LOGGER .error (
81
- f"[create_unified_cost_jobs_by_domain_config] error: { e } " ,
81
+ f"[create_unified_cost_jobs_by_domain_config] domain_id : { domain_id } , error: { e } " ,
82
82
exc_info = True ,
83
83
)
84
84
@@ -134,7 +134,9 @@ def run_unified_cost(self, params: dict):
134
134
workspace_ids = self ._get_workspace_ids (domain_id )
135
135
136
136
try :
137
+
137
138
for workspace_id in workspace_ids :
139
+ unified_cost_created_at = datetime .utcnow ()
138
140
self .create_unified_cost_with_workspace (
139
141
exchange_source ,
140
142
domain_id ,
@@ -144,6 +146,13 @@ def run_unified_cost(self, params: dict):
144
146
aggregation_date ,
145
147
is_confirmed ,
146
148
)
149
+ self ._delete_old_unified_costs (
150
+ domain_id ,
151
+ workspace_id ,
152
+ aggregation_month ,
153
+ is_confirmed ,
154
+ unified_cost_created_at ,
155
+ )
147
156
148
157
self .unified_cost_job_mgr .update_is_confirmed_unified_cost_job (
149
158
unified_cost_job_vo , is_confirmed
@@ -382,7 +391,6 @@ def create_unified_cost_with_workspace(
382
391
383
392
exchange_date_str = exchange_date .strftime ("%Y-%m-%d" )
384
393
aggregation_date_str = aggregation_date .strftime ("%Y-%m-%d" )
385
- unified_cost_created_at = datetime .utcnow ()
386
394
387
395
row_count = 0
388
396
for row in cursor :
@@ -439,13 +447,6 @@ def create_unified_cost_with_workspace(
439
447
_LOGGER .debug (
440
448
f"[create_unified_cost_with_workspace] create count: { row_count } (workspace_id: { workspace_id } )"
441
449
)
442
- self ._delete_old_unified_costs (
443
- domain_id ,
444
- workspace_id ,
445
- unified_cost_billed_month ,
446
- is_confirmed ,
447
- unified_cost_created_at ,
448
- )
449
450
450
451
def _get_data_source_currency_map (
451
452
self , domain_id : str , workspace_id : str
@@ -505,14 +506,10 @@ def _delete_old_unified_costs(
505
506
{"key" : "billed_month" , "value" : unified_cost_month , "operator" : "eq" },
506
507
{"key" : "is_confirmed" , "value" : is_confirmed , "operator" : "eq" },
507
508
{"key" : "domain_id" , "value" : domain_id , "operator" : "eq" },
509
+ {"key" : "created_at" , "value" : created_at , "operator" : "lt" },
508
510
],
509
511
}
510
512
511
- if not is_confirmed :
512
- query_filter ["filter" ].append (
513
- {"key" : "created_at" , "value" : created_at , "operator" : "lt" }
514
- )
515
-
516
513
_LOGGER .debug (
517
514
f"[delete_old_unified_costs] delete query filter conditions: { query_filter } "
518
515
)
@@ -522,7 +519,7 @@ def _delete_old_unified_costs(
522
519
)
523
520
524
521
_LOGGER .debug (
525
- f"[delete_old_unified_costs] delete count: { total_count } ({ unified_cost_month } )({ workspace_id } )"
522
+ f"[delete_old_unified_costs] delete count: { total_count } ({ unified_cost_month } )({ workspace_id } , is_confirmed: { is_confirmed } )"
526
523
)
527
524
unified_cost_vos .delete ()
528
525
@@ -544,16 +541,18 @@ def _get_unified_cost_job(
544
541
self , domain_id : str , aggregation_month : str
545
542
) -> UnifiedCostJob :
546
543
547
- unified_cost_job_vo = self .unified_cost_job_mgr .filter_unified_cost_jobs (
544
+ unified_cost_job_vos = self .unified_cost_job_mgr .filter_unified_cost_jobs (
548
545
domain_id = domain_id , billed_month = aggregation_month
549
546
)
550
- if not unified_cost_job_vo :
547
+ if not unified_cost_job_vos :
551
548
unified_cost_job_vo = self .unified_cost_job_mgr .create_unified_cost (
552
549
{
553
550
"domain_id" : domain_id ,
554
551
"billed_month" : aggregation_month ,
555
552
}
556
553
)
554
+ else :
555
+ unified_cost_job_vo = unified_cost_job_vos [0 ]
557
556
return unified_cost_job_vo
558
557
559
558
def _get_aggregation_date (
0 commit comments