diff --git a/auto_pt/views.py b/auto_pt/views.py index e51c768..01f1024 100644 --- a/auto_pt/views.py +++ b/auto_pt/views.py @@ -14,8 +14,6 @@ from pt_site.views import scheduler, pt_spider from ptools.base import CommonResponse, StatusCodeEnum - - def add_task(request): if request.method == 'POST': content = json.loads(request.body.decode()) # 接收参数 @@ -175,17 +173,19 @@ def get_update_logs(): def update_page(request): - cid = '' - restart = 'false' - delta = '程序未在容器中启动?' - # 获取docker对象 - client = docker.from_env() - # 从内部获取容器id - for c in client.api.containers(): - if 'ngfchl/ptools' in c.get('Image'): - cid = c.get('Id') - delta = c.get('Status') - restart = 'true' + try: + # 获取docker对象 + client = docker.from_env() + # 从内部获取容器id + for c in client.api.containers(): + if 'ngfchl/ptools' in c.get('Image'): + cid = c.get('Id') + delta = c.get('Status') + restart = 'true' + except Exception as e: + cid = '' + restart = 'false' + delta = '程序未在容器中启动?' if get_update_logs(): update = 'false' update_tips = '目前您使用的是最新版本!' @@ -277,7 +277,7 @@ def do_restart(request): # client.api.inspect_container(cid) # StartedAt = client.api.inspect_container(cid).get('State').get('StartedAt') return JsonResponse(data=CommonResponse.error( - msg='重启指令发送成功,容器重启中 ...' + msg='重启指令发送成功,容器重启中 ... 15秒后自动刷新页面 ...' ).to_dict(), safe=False) except Exception as e: return JsonResponse(data=CommonResponse.error( diff --git a/templates/auto_pt/update.html b/templates/auto_pt/update.html index b49f855..fb18ffc 100644 --- a/templates/auto_pt/update.html +++ b/templates/auto_pt/update.html @@ -47,6 +47,7 @@ {{ update_tips }} + 容器已运行:{{ delta }} + @@ -123,6 +124,7 @@ update: {{ update }}, local_log_width: 24, cid: "{{ cid }}", + time: '' }, created() { if (this.update) { @@ -136,11 +138,20 @@ message: "{{ update_tips }}", type: 'success' }); - } - , + }, + watch: { + time: function (newValue) { + if (newValue == 0) { + this.$router.push("{% url "update_page" %}") + } + } + }, methods: { + timeDown() { + this.time-- + }, do_restart() { - this.$confirm('此操作将重启容器,并更新软件, 是否继续?', '提示', { + this.$confirm('重启容器, 是否继续?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' @@ -153,6 +164,8 @@ type: 'success', message: res.data.msg }); + this.time = 15 + setInterval(this.timeDown, 1000) } else { console.log(res) this.$message({ @@ -171,7 +184,7 @@ }, do_update() { - this.$confirm('此操作会拉取软件更新软件,并重启容器,是否继续?', '提示', { + this.$confirm('此操作会拉取代码并更新软件,并重启容器,是否继续?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' @@ -191,6 +204,8 @@ type: 'success', message: res.data.msg }); + this.time = 15 + setInterval(this.timeDown, 1000) } else { console.log(res, 2) this.$message({