mirror of https://github.com/openspug/spug
parent
f421729752
commit
5bd1f48172
|
@ -7,6 +7,7 @@ from apscheduler.triggers.interval import IntervalTrigger
|
|||
from django_redis import get_redis_connection
|
||||
from django.conf import settings
|
||||
from django.db import connections
|
||||
from django.db.utils import DatabaseError
|
||||
from apps.monitor.models import Detection
|
||||
from libs import AttrDict, human_datetime
|
||||
from datetime import datetime, timedelta
|
||||
|
@ -32,6 +33,7 @@ class Scheduler:
|
|||
|
||||
def _init(self):
|
||||
self.scheduler.start()
|
||||
try:
|
||||
for item in Detection.objects.filter(is_active=True):
|
||||
now = datetime.now()
|
||||
trigger = IntervalTrigger(minutes=int(item.rate), timezone=self.timezone)
|
||||
|
@ -43,6 +45,8 @@ class Scheduler:
|
|||
next_run_time=now + timedelta(seconds=randint(0, 60))
|
||||
)
|
||||
connections.close_all()
|
||||
except DatabaseError:
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
rds_cli = get_redis_connection()
|
||||
|
|
|
@ -8,6 +8,7 @@ from apscheduler.triggers.date import DateTrigger
|
|||
from apscheduler.triggers.cron import CronTrigger
|
||||
from django_redis import get_redis_connection
|
||||
from django.db import connections
|
||||
from django.db.utils import DatabaseError
|
||||
from apps.schedule.models import Task, History
|
||||
from apps.schedule.builtin import auto_run_by_day, auto_run_by_minute
|
||||
from django.conf import settings
|
||||
|
@ -78,6 +79,7 @@ class Scheduler:
|
|||
def _init(self):
|
||||
self.scheduler.start()
|
||||
self._init_builtin_jobs()
|
||||
try:
|
||||
for task in Task.objects.filter(is_active=True):
|
||||
trigger = self.parse_trigger(task.trigger, task.trigger_args)
|
||||
self.scheduler.add_job(
|
||||
|
@ -87,6 +89,8 @@ class Scheduler:
|
|||
args=(task.id, task.command, json.loads(task.targets)),
|
||||
)
|
||||
connections.close_all()
|
||||
except DatabaseError:
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
rds_cli = get_redis_connection()
|
||||
|
|
Loading…
Reference in New Issue