From 821b62ce46f6fce44513a5781eca4a3c49a0ca53 Mon Sep 17 00:00:00 2001 From: vapao Date: Mon, 14 Sep 2020 18:52:01 +0800 Subject: [PATCH] =?UTF-8?q?U=20=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E5=8F=91=E5=B8=83=E7=94=B3=E8=AF=B7=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/deploy/utils.py | 12 +++++++++++- spug_api/apps/schedule/scheduler.py | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spug_api/apps/deploy/utils.py b/spug_api/apps/deploy/utils.py index 8fbf09c..28680fc 100644 --- a/spug_api/apps/deploy/utils.py +++ b/spug_api/apps/deploy/utils.py @@ -3,10 +3,12 @@ # Released under the AGPL-3.0 License. from django_redis import get_redis_connection from django.conf import settings -from libs.utils import AttrDict, human_time, human_datetime +from libs.utils import AttrDict, human_time, human_datetime, parse_time from apps.host.models import Host from apps.notify.models import Notify +from apps.deploy.models import DeployRequest from concurrent import futures +from datetime import datetime import requests import subprocess import json @@ -458,3 +460,11 @@ class Helper: self.send_info(key, out) if code != 0: self.send_error(key, f'exit code: {code}') + + +def auto_update_status(): + now = datetime.now() + for req in DeployRequest.objects.filter(status='2'): + if (now - parse_time(req.do_at)).seconds > 3600: + req.status = '-3' + req.save() diff --git a/spug_api/apps/schedule/scheduler.py b/spug_api/apps/schedule/scheduler.py index 319792c..a217f1a 100644 --- a/spug_api/apps/schedule/scheduler.py +++ b/spug_api/apps/schedule/scheduler.py @@ -16,6 +16,7 @@ from apps.notify.models import Notify from apps.schedule.executors import dispatch from apps.schedule.utils import auto_clean_schedule_history from apps.alarm.utils import auto_clean_records +from apps.deploy.utils import auto_update_status from django.conf import settings from libs import AttrDict, human_datetime import logging @@ -89,6 +90,7 @@ class Scheduler: def _init_builtin_jobs(self): self.scheduler.add_job(auto_clean_records, 'cron', hour=0, minute=0) self.scheduler.add_job(auto_clean_schedule_history, 'cron', hour=0, minute=0) + self.scheduler.add_job(auto_update_status, 'interval', minutes=5) def _init(self): self.scheduler.start()