From 9a8881f5e1f2f99d29676a37859727151a9a3fd0 Mon Sep 17 00:00:00 2001 From: ngfchl Date: Thu, 1 Sep 2022 15:44:18 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BC=98=E5=8C=96=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=AE=B9=E5=99=A8=E5=90=AF=E5=8A=A8=E6=97=B6=E9=97=B4=EF=BC=8C?= =?UTF-8?q?=E5=8F=AA=E7=AE=A1=E7=9C=8B=E5=88=B0=E5=AE=B9=E5=99=A8=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E9=87=8D=E5=90=AF=202.=20=E6=9C=AC=E6=AC=A1=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=87=8D=E5=90=AF=E5=90=8E=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auto_pt/views.py | 14 +++++++++----- templates/auto_pt/restart.html | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/auto_pt/views.py b/auto_pt/views.py index 3b7a942..904aaf1 100644 --- a/auto_pt/views.py +++ b/auto_pt/views.py @@ -5,6 +5,7 @@ from datetime import datetime import docker import git +import pytz from django.http import JsonResponse from django.shortcuts import render @@ -169,12 +170,14 @@ def restart_container(request): client = docker.from_env() # 从内部获取容器id cid = socket.gethostname() + client.api.info() started_at = client.api.inspect_container(cid).get('State').get('StartedAt')[:19] - UTC_FORMAT = "%Y-%m-%dT%H:%M:%S" - utc_time = datetime.strptime(started_at, UTC_FORMAT) - delta = (datetime.now() - utc_time).seconds + utc_format = "%Y-%m-%dT%H:%M:%S:%fZ" + restart = 'true' + delta = datetime.strptime(started_at, utc_format).astimezone(pytz.UTC) except Exception as e: - delta = '请确认项目是否在容器中运行?' + restart = 'false' + delta = '程序未在容器中启动?' if get_update_logs(): update = 'false' update_tips = '目前您使用的是最新版本!' @@ -184,6 +187,7 @@ def restart_container(request): return render(request, 'auto_pt/restart.html', context={ 'delta': delta, + 'restart': restart, 'local_logs': get_git_logs(), 'update_notes': get_git_logs(master='origin/master'), 'update': update, @@ -235,7 +239,7 @@ def do_update_xpath(request): del site['pk'] site_obj = Site.objects.update_or_create(defaults=site, url=site.get('url')) print(site_obj) - xpath_update.append(site_obj[0].name + ' 规则新增成功!' if site_obj[1] else '更新成功!') + xpath_update.append(site_obj[0].name + (' 规则新增成功!' if site_obj[1] else '更新成功!')) return JsonResponse(data=CommonResponse.success( msg='更新成功!!', data={ diff --git a/templates/auto_pt/restart.html b/templates/auto_pt/restart.html index 3c3e64f..cc76995 100644 --- a/templates/auto_pt/restart.html +++ b/templates/auto_pt/restart.html @@ -42,7 +42,7 @@ width="200" trigger="hover" content="只有在容器中部署才能使用本操作,其他环境部署无效"> - 重启容器 + 重启容器