mirror of https://github.com/openspug/spug
U 自动更新超时发布申请状态
parent
a57e5eb009
commit
821b62ce46
|
@ -3,10 +3,12 @@
|
||||||
# Released under the AGPL-3.0 License.
|
# Released under the AGPL-3.0 License.
|
||||||
from django_redis import get_redis_connection
|
from django_redis import get_redis_connection
|
||||||
from django.conf import settings
|
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.host.models import Host
|
||||||
from apps.notify.models import Notify
|
from apps.notify.models import Notify
|
||||||
|
from apps.deploy.models import DeployRequest
|
||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
|
from datetime import datetime
|
||||||
import requests
|
import requests
|
||||||
import subprocess
|
import subprocess
|
||||||
import json
|
import json
|
||||||
|
@ -458,3 +460,11 @@ class Helper:
|
||||||
self.send_info(key, out)
|
self.send_info(key, out)
|
||||||
if code != 0:
|
if code != 0:
|
||||||
self.send_error(key, f'exit code: {code}')
|
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()
|
||||||
|
|
|
@ -16,6 +16,7 @@ from apps.notify.models import Notify
|
||||||
from apps.schedule.executors import dispatch
|
from apps.schedule.executors import dispatch
|
||||||
from apps.schedule.utils import auto_clean_schedule_history
|
from apps.schedule.utils import auto_clean_schedule_history
|
||||||
from apps.alarm.utils import auto_clean_records
|
from apps.alarm.utils import auto_clean_records
|
||||||
|
from apps.deploy.utils import auto_update_status
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from libs import AttrDict, human_datetime
|
from libs import AttrDict, human_datetime
|
||||||
import logging
|
import logging
|
||||||
|
@ -89,6 +90,7 @@ class Scheduler:
|
||||||
def _init_builtin_jobs(self):
|
def _init_builtin_jobs(self):
|
||||||
self.scheduler.add_job(auto_clean_records, 'cron', hour=0, minute=0)
|
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_clean_schedule_history, 'cron', hour=0, minute=0)
|
||||||
|
self.scheduler.add_job(auto_update_status, 'interval', minutes=5)
|
||||||
|
|
||||||
def _init(self):
|
def _init(self):
|
||||||
self.scheduler.start()
|
self.scheduler.start()
|
||||||
|
|
Loading…
Reference in New Issue