From e97917751a5a54d93ea8bdfb79768b2049a2982f Mon Sep 17 00:00:00 2001 From: ImMin5 Date: Thu, 26 Oct 2023 02:11:27 +0900 Subject: [PATCH] feat: modify task unit count Signed-off-by: ImMin5 --- Dockerfile | 2 +- src/cloudforet/cost_analysis/manager/cost_manager.py | 5 +++-- src/cloudforet/cost_analysis/manager/job_manager.py | 9 +++++++-- src/cloudforet/cost_analysis/model/job_model.py | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index c9f282e..9864e4e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM cloudforet/python-core:2 +FROM cloudforet/python-core:1.12 ENV PYTHONUNBUFFERED 1 ENV SPACEONE_PORT 50051 diff --git a/src/cloudforet/cost_analysis/manager/cost_manager.py b/src/cloudforet/cost_analysis/manager/cost_manager.py index 8356087..a58c33a 100644 --- a/src/cloudforet/cost_analysis/manager/cost_manager.py +++ b/src/cloudforet/cost_analysis/manager/cost_manager.py @@ -32,8 +32,9 @@ def get_data(self, options, secret_data, schema, task_options): parameters = self._make_parameters(_start, _end, options) start_time = time.time() - _LOGGER.info(f'[get_data] start to collect data from {_start} to {_end}') + _LOGGER.info(f'[get_data] {tenant_ids} start to collect data from {_start} to {_end}') for idx, tenant_id in enumerate(tenant_ids): + _LOGGER.info(f'[get_data] #{idx+1} {tenant_id} tenant start to collect data from {_start} to {_end}') scope = self._make_scope(secret_data, task_options, collect_scope, tenant_id) blobs = self.azure_cm_connector.begin_create_operation(scope, parameters) @@ -181,7 +182,7 @@ def _get_tenant_ids(task_options, collect_scope): if 'tenant_id' in task_options: tenant_ids.append(task_options['tenant_id']) elif collect_scope == 'customer_tenant_id': - tenant_ids.append(task_options['customer_tenant']) + tenant_ids.append(task_options['customer_tenants']) else: tenant_ids.append('EA Agreement') return tenant_ids diff --git a/src/cloudforet/cost_analysis/manager/job_manager.py b/src/cloudforet/cost_analysis/manager/job_manager.py index b40d6b5..3607fc7 100644 --- a/src/cloudforet/cost_analysis/manager/job_manager.py +++ b/src/cloudforet/cost_analysis/manager/job_manager.py @@ -1,4 +1,5 @@ import logging +import math from datetime import datetime, timedelta from dateutil.relativedelta import relativedelta @@ -10,6 +11,7 @@ _LOGGER = logging.getLogger(__name__) +_TASK_LIST_SIZE = 4 class JobManager(BaseManager): @@ -35,11 +37,14 @@ def get_tasks(self, options, secret_data, schema, start, last_synchronized_at, d if len(customer_tenants) == 0: raise ERROR_EMPTY_CUSTOMER_TENANTS(customer_tenants=customer_tenants) - for customer_tenant in customer_tenants: + tenant_size = math.ceil(len(customer_tenants)/_TASK_LIST_SIZE) + divided_customer_tenants = [customer_tenants[i:i + tenant_size] for i in range(0, len(customer_tenants), tenant_size)] + + for divided_customer_tenant in divided_customer_tenants: tasks.append({'task_options': {'start': start_month, 'account_agreement_type': billing_account_agreement_type, 'collect_scope': 'customer_tenant_id', - 'customer_tenant': customer_tenant}}) + 'customer_tenants': divided_customer_tenant}}) changed.append({'start': start_month}) else: tasks = [{'task_options': {'start': start_month, 'account_agreement_type': billing_account_agreement_type, diff --git a/src/cloudforet/cost_analysis/model/job_model.py b/src/cloudforet/cost_analysis/model/job_model.py index 2870333..1fb17d1 100644 --- a/src/cloudforet/cost_analysis/model/job_model.py +++ b/src/cloudforet/cost_analysis/model/job_model.py @@ -10,7 +10,7 @@ class TaskOptionsWithSubscription(Model): class TaskOptionsWithCustomerTenant(Model): - customer_tenant = StringType(serialize_when_none=False) + customer_tenants = ListType(StringType, serialize_when_none=False) class TaskOptions(TaskOptionsWithSubscription, TaskOptionsWithCustomerTenant):