From 480d37ffb80dd029b5d74d2793019acfbdac4c9f Mon Sep 17 00:00:00 2001 From: Jongmin Kim Date: Mon, 11 Sep 2023 20:31:20 +0900 Subject: [PATCH] refactor: refacto job close logic --- .../cost_analysis/service/job_service.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/spaceone/cost_analysis/service/job_service.py b/src/spaceone/cost_analysis/service/job_service.py index a6a0bbfe..0acba644 100644 --- a/src/spaceone/cost_analysis/service/job_service.py +++ b/src/spaceone/cost_analysis/service/job_service.py @@ -438,19 +438,24 @@ def _close_job(self, job_id, domain_id, data_source_id): self._delete_changed_cost_data(job_vo, changed_vo.start, changed_vo.end, changed_vo.filter) except Exception as e: + _LOGGER.error(f'[_close_job] aggregate cost data error: {e}', exc_info=True) self._rollback_cost_data(job_vo) self.job_mgr.change_error_status(job_vo, e) raise e - self.cost_mgr.remove_stat_cache(domain_id, data_source_id) + try: + self.cost_mgr.remove_stat_cache(domain_id, data_source_id) - if not no_preload_cache: - self.job_mgr.preload_cost_stat_queries(domain_id, data_source_id) + if not no_preload_cache: + self.job_mgr.preload_cost_stat_queries(domain_id, data_source_id) - self.budget_usage_mgr.update_budget_usage(domain_id, data_source_id) + self.budget_usage_mgr.update_budget_usage(domain_id, data_source_id) - self._update_last_sync_time(job_vo) - self.job_mgr.change_success_status(job_vo) + self._update_last_sync_time(job_vo) + self.job_mgr.change_success_status(job_vo) + except Exception as e: + _LOGGER.error(f'[_close_job] cache and budget update error: {e}', exc_info=True) + self.job_mgr.change_error_status(job_vo, e) elif job_vo.status == 'ERROR': self._rollback_cost_data(job_vo)