Merge branch 'develop' of github.com:saltstack/salt into develop

This commit is contained in:
Pedro Algarvio 2013-01-16 23:19:27 +00:00
commit 62d69de30e
2 changed files with 18 additions and 4 deletions

View File

@ -165,12 +165,14 @@ class Master(SMaster):
'''
jid_root = os.path.join(self.opts['cachedir'], 'jobs')
search = salt.search.Search(self.opts)
last = time.time()
last = int(time.time())
fileserver = salt.fileserver.Fileserver(self.opts)
runners = salt.loader.runner(self.opts)
schedule = salt.utils.schedule.Schedule(self.opts, runners)
while True:
if self.opts['keep_jobs'] != 0:
now = int(time.time())
loop_interval = int(self.opts['loop_interval'])
if self.opts['keep_jobs'] != 0 and (now - last) >= loop_interval:
cur = '{0:%Y%m%d%H}'.format(datetime.datetime.now())
for top in os.listdir(jid_root):
@ -188,7 +190,6 @@ class Master(SMaster):
elif int(cur) - int(jid[:10]) > self.opts['keep_jobs']:
shutil.rmtree(f_path)
if self.opts.get('search'):
now = time.time()
if now - last > self.opts['search_index_interval']:
search.index()
try:
@ -199,12 +200,16 @@ class Master(SMaster):
)
try:
schedule.eval()
# Check if scheduler requires lower loop interval than
# the loop_interval setting
if schedule.loop_interval < loop_interval:
loop_interval = schedule.loop_interval
except Exception as exc:
log.error(
'Exception {0} occured in scheduled job'.format(exc)
)
try:
time.sleep(int(self.opts['loop_interval']))
time.sleep(loop_interval)
except KeyboardInterrupt:
break

View File

@ -23,6 +23,7 @@ import time
import datetime
import multiprocessing
import threading
import sys
class Schedule(object):
@ -41,6 +42,8 @@ class Schedule(object):
else:
self.returners = {}
self.schedule_returner = self.option('schedule_returner')
# Keep track of the lowest loop interval needed in this variable
self.loop_interval = sys.maxint
def option(self, opt):
'''
@ -110,6 +113,12 @@ class Schedule(object):
seconds += int(data.get('minutes', 0)) * 60
seconds += int(data.get('hours', 0)) * 3600
seconds += int(data.get('days', 0)) * 86400
# Check if the seconds variable is lower than current lowest
# loop interval needed. If it is lower then overwrite variable
# external loops using can then check this variable for how often
# they need to reschedule themselves
if seconds < self.loop_interval:
self.loop_interval = seconds
now = int(time.time())
run = False
if job in self.intervals: