Skip to content

Commit

Permalink
Moved the check of in_progress to update es method
Browse files Browse the repository at this point in the history
  • Loading branch information
athiruma committed Oct 3, 2023
1 parent 62f3dd7 commit 55cfd3b
Showing 1 changed file with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,36 +203,36 @@ def __upload_cro_report_to_es(self, monitor_data: dict):
"""
upload_data = {}
for ticket_id, instance_data in monitor_data.items():
if self.__check_value_in_es(tag_key='ticket_id_state', tag_value='in-progress', ticket_id=ticket_id):
ticket_id = ticket_id.split('-')[-1]
user = instance_data[self.ZERO].get('user')
user_project = instance_data[self.ZERO].get('project')
issue_description = self.jira_operations.get_issue_description(ticket_id=ticket_id, state='ANY')
ticket_opened_date = issue_description.get('TicketOpenedDate')
group_by_tag_name = self.COST_EXPLORER_TAGS[self.TICKET_ID_KEY]
user_cost = self.get_user_cost_data(group_by_tag_name=group_by_tag_name, group_by_tag_value=ticket_id,
requested_date=ticket_opened_date)
duration = int(instance_data[self.ZERO].get('duration', 0))
user_forecast = self.get_user_cost_data(group_by_tag_name=group_by_tag_name, group_by_tag_value=ticket_id, requested_date=datetime.utcnow(), extra_filter_key_values={'Project': user_project}, forecast=True, duration=duration)
cost_estimation = float(instance_data[self.ZERO].get('estimated_cost', self.ZERO))
if self.__cost_over_usage.es_operations.verify_elastic_index_doc_id(index=self.__cost_over_usage.es_index_cro, doc_id=ticket_id):
ticket_id = ticket_id.split('-')[-1]
user = instance_data[self.ZERO].get('user')
user_project = instance_data[self.ZERO].get('project')
issue_description = self.jira_operations.get_issue_description(ticket_id=ticket_id, state='ANY')
ticket_opened_date = issue_description.get('TicketOpenedDate')
group_by_tag_name = self.COST_EXPLORER_TAGS[self.TICKET_ID_KEY]
user_cost = self.get_user_cost_data(group_by_tag_name=group_by_tag_name, group_by_tag_value=ticket_id,
requested_date=ticket_opened_date)
duration = int(instance_data[self.ZERO].get('duration', 0))
user_forecast = self.get_user_cost_data(group_by_tag_name=group_by_tag_name, group_by_tag_value=ticket_id, requested_date=datetime.utcnow(), extra_filter_key_values={'Project': user_project}, forecast=True, duration=duration)
cost_estimation = float(instance_data[self.ZERO].get('estimated_cost', self.ZERO))
if self.__cost_over_usage.es_operations.verify_elastic_index_doc_id(index=self.__cost_over_usage.es_index_cro, doc_id=ticket_id):
if self.__check_value_in_es(tag_key='ticket_id_state', tag_value='in-progress', ticket_id=ticket_id):
es_data = self.__cost_over_usage.es_operations.get_es_data_by_id(id=ticket_id, index=self.__cost_over_usage.es_index_cro)
es_data['_source']['ticket_opened_date'] = ticket_opened_date.date()
es_data['_source']['forecast'] = user_forecast
es_data['_source']['user'] = user
source = self.__prepare_update_es_data(source=es_data.get('_source'), instance_data=instance_data, cost_estimation=cost_estimation, user_cost=user_cost)
self.__cost_over_usage.es_operations.update_elasticsearch_index(index=self.__es_index_cro, id=ticket_id, metadata=source)
upload_data[ticket_id] = source
else:
if ticket_id not in upload_data:
source = self.prepare_instance_data(instance_data=instance_data, ticket_id=ticket_id, cost_estimation=cost_estimation, user=user, user_cost=user_cost, ticket_opened_date=ticket_opened_date)
source['ticket_opened_date'] = ticket_opened_date.date()
source['forecast'] = user_forecast
source['user'] = user
if not source.get(self.ALLOCATED_BUDGET):
source[self.ALLOCATED_BUDGET] = self.get_account_budget_from_payer_ce_report()
self.__cost_over_usage.es_operations.upload_to_elasticsearch(index=self.__es_index_cro, data=source, id=ticket_id)
upload_data[ticket_id] = source
else:
if ticket_id not in upload_data:
source = self.prepare_instance_data(instance_data=instance_data, ticket_id=ticket_id, cost_estimation=cost_estimation, user=user, user_cost=user_cost, ticket_opened_date=ticket_opened_date)
source['ticket_opened_date'] = ticket_opened_date.date()
source['forecast'] = user_forecast
source['user'] = user
if not source.get(self.ALLOCATED_BUDGET):
source[self.ALLOCATED_BUDGET] = self.get_account_budget_from_payer_ce_report()
self.__cost_over_usage.es_operations.upload_to_elasticsearch(index=self.__es_index_cro, data=source, id=ticket_id)
upload_data[ticket_id] = source
return upload_data

@logger_time_stamp
Expand Down

0 comments on commit 55cfd3b

Please sign in to comment.