From f5a2602539a90da23398c6b451b8ba4f01bd8016 Mon Sep 17 00:00:00 2001 From: Jose Javier Merchante Date: Tue, 30 Jul 2024 17:52:59 +0200 Subject: [PATCH] Include days spent in collection phase logs When the collection phase is finished and the spent time is more than one day, days are missing in the logs. It is now fixed and included in the logs. Signed-off-by: Jose Javier Merchante --- releases/unreleased/days-in-collection-spent-time.yml | 8 ++++++++ sirmordred/task_collection.py | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 releases/unreleased/days-in-collection-spent-time.yml diff --git a/releases/unreleased/days-in-collection-spent-time.yml b/releases/unreleased/days-in-collection-spent-time.yml new file mode 100644 index 00000000..b563ce40 --- /dev/null +++ b/releases/unreleased/days-in-collection-spent-time.yml @@ -0,0 +1,8 @@ +--- +title: Days in collection spent time +category: fixed +author: Jose Javier Merchante +issue: null +notes: > + Include days in logs when the collection spent time is more than + one day. diff --git a/sirmordred/task_collection.py b/sirmordred/task_collection.py index fac2e397..47eb875f 100644 --- a/sirmordred/task_collection.py +++ b/sirmordred/task_collection.py @@ -22,13 +22,14 @@ # import logging -import time import traceback from grimoire_elk.elk import feed_backend from grimoire_elk.elastic_items import ElasticItems from grimoire_elk.elastic import ElasticSearch +from grimoirelab_toolkit.datetime import datetime_utcnow + from sirmordred.error import DataCollectionError from sirmordred.task import Task from sirmordred.task_projects import TaskProjects @@ -74,7 +75,7 @@ def execute(self): logging.info('%s collect disabled', self.backend_section) return errors - t2 = time.time() + time_start = datetime_utcnow() logger.info('[%s] collection phase starts', self.backend_section) print("Collection for {}: starting...".format(self.backend_section)) clean = False @@ -142,8 +143,7 @@ def execute(self): raise DataCollectionError('Failed to collect data from %s' % url) logger.info('[%s] collection finished for %s', self.backend_section, self.anonymize_url(repo)) - t3 = time.time() - spent_time = time.strftime("%H:%M:%S", time.gmtime(t3 - t2)) + spent_time = str(datetime_utcnow() - time_start).split('.')[0] logger.info('[%s] collection phase finished in %s', self.backend_section, spent_time) print("Collection for {}: finished after {} hours".format(self.backend_section,