diff --git a/oedp/src/commands/run/run_cmd.py b/oedp/src/commands/run/run_cmd.py index be38854871924bf56bb7246f0eeef5344847e7aa..b839138e6664254cf59eb412eaa2e804af0c60b0 100644 --- a/oedp/src/commands/run/run_cmd.py +++ b/oedp/src/commands/run/run_cmd.py @@ -11,10 +11,13 @@ # Create: 2024-12-23 # ====================================================================================================================== +import time + from src.commands.run.run_action import RunAction from src.exceptions.config_exception import ConfigException from src.utils.log.logger_generator import LoggerGenerator from src.utils.main_reader import MainReader +from decimal import Decimal class RunCmd: @@ -35,15 +38,25 @@ class RunCmd: :return: 是否执行成功 """ - self.log.debug(f'Running cmd run: action={self.action}, project={self.project}') + start_time = time.time() + self.log.info(f'Start time: {time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(start_time))}') try: - main = MainReader(self.project) - action = main.get_action_detail(self.action) - except ConfigException as e: - self.log.error(f'Failed to get project main info: {e}') - return False - if 'tasks' not in action: - self.log.error(f'Failed to get tasks info: {action}') - return False - tasks = action['tasks'] - return RunAction(self.project, self.action, tasks).run() + self.log.debug(f'Running cmd run: action={self.action}, project={self.project}') + try: + main = MainReader(self.project) + action = main.get_action_detail(self.action) + except ConfigException as e: + self.log.error(f'Failed to get project main info: {e}') + return False + if 'tasks' not in action: + self.log.error(f'Failed to get tasks info: {action}') + return False + tasks = action['tasks'] + return RunAction(self.project, self.action, tasks).run() + finally: + end_time = time.time() + seconds = Decimal(f"{format(end_time - start_time, '.1f')}") + formatted_time = time.strftime("%H:%M:%S", time.gmtime(float(seconds))) + elapsed_time = f"{formatted_time}.{int((seconds % 1) * 10)}" + self.log.info(f'End time: {time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(end_time))}') + self.log.info(f'Elapsed time: {elapsed_time}')