From 6709feffeb86c3082dec9dc8074f35ac8d842f75 Mon Sep 17 00:00:00 2001 From: vapao Date: Sat, 22 Oct 2022 17:48:46 +0800 Subject: [PATCH] =?UTF-8?q?U=20=E4=BC=98=E5=8C=96=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=B1=95=E7=A4=BA=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/deploy/utils.py | 18 ++++++++++++------ spug_api/apps/exec/executors.py | 2 +- spug_api/apps/repository/utils.py | 7 +++++-- spug_web/src/pages/deploy/request/Console.js | 8 +++++--- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/spug_api/apps/deploy/utils.py b/spug_api/apps/deploy/utils.py index a2fa2ac..9473fb8 100644 --- a/spug_api/apps/deploy/utils.py +++ b/spug_api/apps/deploy/utils.py @@ -4,7 +4,7 @@ from django_redis import get_redis_connection from django.conf import settings from django.db import close_old_connections -from libs.utils import AttrDict, render_str +from libs.utils import AttrDict, render_str, human_seconds_time from apps.host.models import Host from apps.config.utils import compose_configs from apps.repository.models import Repository @@ -15,6 +15,7 @@ from concurrent import futures from functools import partial import json import uuid +import time import os REPOS_DIR = settings.REPOS_DIR @@ -131,6 +132,7 @@ def _ext1_deploy(req, helper, env): def _ext2_deploy(req, helper, env): + flag = time.time() extend, step = req.deploy.extend_obj, 1 host_actions = json.loads(extend.host_actions) server_actions = json.loads(extend.server_actions) @@ -192,8 +194,9 @@ def _ext2_deploy(req, helper, env): helper.send_info('local', '打包完成\r\n') helper.add_callback(partial(os.remove, os.path.join(sp_dir, tar_gz_file))) + human_time = human_seconds_time(time.time() - flag) if host_actions: - helper.send_success('local', '\r\n** 执行完成 **', status='success') + helper.send_success('local', f'\r\n** 执行完成,耗时:{human_time} **', status='success') if req.deploy.is_parallel: threads, latest_exception = [], None max_workers = max(10, os.cpu_count() * 5) @@ -230,10 +233,11 @@ def _ext2_deploy(req, helper, env): raise e else: req.fail_host_ids = [] - helper.send_success('local', '\r\n** 发布成功 **', status='success') + helper.send_success('local', f'\r\n** 发布成功,耗时:{human_time} **', status='success') def _deploy_ext1_host(req, helper, h_id, env): + flag = time.time() helper.send_clear(h_id) helper.send_info(h_id, '数据准备... ', status='doing') host = Host.objects.filter(pk=h_id).first() @@ -292,10 +296,12 @@ def _deploy_ext1_host(req, helper, h_id, env): command = f'cd {extend.dst_dir} && {extend.hook_post_host}' helper.remote(host.id, ssh, command) - helper.send_success(h_id, '\r\n** 发布成功 **', status='success') + human_time = human_seconds_time(time.time() - flag) + helper.send_success(h_id, f'\r\n** 发布成功,耗时:{human_time} **', status='success') def _deploy_ext2_host(helper, h_id, actions, env, spug_version): + flag = time.time() host = Host.objects.filter(pk=h_id).first() if not host: helper.send_error(h_id, 'no such host') @@ -339,5 +345,5 @@ def _deploy_ext2_host(helper, h_id, actions, env, spug_version): helper.send_info(h_id, f'{action["title"]}...\r\n') command = f'cd /tmp && {action["data"]}' helper.remote(host.id, ssh, command) - - helper.send_success(h_id, f'\r\n** 发布成功 **', status='success') + human_time = human_seconds_time(time.time() - flag) + helper.send_success(h_id, f'\r\n** 发布成功,耗时:{human_time} **', status='success') diff --git a/spug_api/apps/exec/executors.py b/spug_api/apps/exec/executors.py index ffa6f02..5ae962e 100644 --- a/spug_api/apps/exec/executors.py +++ b/spug_api/apps/exec/executors.py @@ -59,7 +59,7 @@ class Job: for code, out in self.ssh.exec_command_with_stream(self.command, self.env): self.send(out) human_time = human_seconds_time(time.time() - flag) - self.send(f'\r\n\x1b[36m** 执行结束,总耗时:{human_time} **\x1b[0m') + self.send(f'\r\n\x1b[36m** 执行结束,耗时:{human_time} **\x1b[0m') except socket.timeout: code = 130 self.send('\r\n\x1b[31m### Time out\x1b[0m') diff --git a/spug_api/apps/repository/utils.py b/spug_api/apps/repository/utils.py index 8fe5e3d..b546912 100644 --- a/spug_api/apps/repository/utils.py +++ b/spug_api/apps/repository/utils.py @@ -4,13 +4,14 @@ from django_redis import get_redis_connection from django.conf import settings from django.db import close_old_connections -from libs.utils import AttrDict, human_datetime, render_str +from libs.utils import AttrDict, human_datetime, render_str, human_seconds_time from apps.repository.models import Repository from apps.app.utils import fetch_repo from apps.config.utils import compose_configs from apps.deploy.helper import Helper import json import uuid +import time import os REPOS_DIR = settings.REPOS_DIR @@ -77,6 +78,7 @@ def dispatch(rep: Repository, helper=None): def _build(rep: Repository, helper, env): + flag = time.time() extend = rep.deploy.extend_obj git_dir = os.path.join(REPOS_DIR, str(rep.deploy_id)) build_dir = os.path.join(REPOS_DIR, rep.spug_version) @@ -115,4 +117,5 @@ def _build(rep: Repository, helper, env): contain = ' '.join(f'{rep.spug_version}/{x}' for x in files) helper.local(f'mkdir -p {BUILD_DIR} && cd {REPOS_DIR} && tar zcf {tar_file} {exclude} {contain}') helper.send_success('local', '完成√\r\n') - helper.send_success('local', '\r\n** 构建成功 **\r\n', status='success') + human_time = human_seconds_time(time.time() - flag) + helper.send_success('local', f'\r\n** 构建成功,耗时:{human_time} **\r\n', status='success') diff --git a/spug_web/src/pages/deploy/request/Console.js b/spug_web/src/pages/deploy/request/Console.js index 09d02c3..68c5ab1 100644 --- a/spug_web/src/pages/deploy/request/Console.js +++ b/spug_web/src/pages/deploy/request/Console.js @@ -239,9 +239,11 @@ function Console(props) { )} )} - - openTerminal(current)}/> - + {cItem.id !== 'local' && ( + + openTerminal(current)}/> + + )}