mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Porting #50216 to fluorine.
This commit is contained in:
parent
303f991f6a
commit
8935e3c58b
@ -975,6 +975,14 @@ class Schedule(object):
|
||||
# last scheduled time in the past.
|
||||
when = _when[0]
|
||||
|
||||
if when < now - loop_interval and \
|
||||
not data.get('_run', False) and \
|
||||
not data.get('run', False) and \
|
||||
not data['_splay']:
|
||||
data['_next_fire_time'] = None
|
||||
data['_continue'] = True
|
||||
return
|
||||
|
||||
if '_run' not in data:
|
||||
# Prevent run of jobs from the past
|
||||
data['_run'] = bool(when >= now - loop_interval)
|
||||
@ -1029,6 +1037,7 @@ class Schedule(object):
|
||||
not data['_splay']:
|
||||
data['_next_fire_time'] = None
|
||||
data['_continue'] = True
|
||||
return
|
||||
|
||||
if '_run' not in data:
|
||||
data['_run'] = True
|
||||
@ -1434,6 +1443,10 @@ class Schedule(object):
|
||||
else:
|
||||
continue
|
||||
|
||||
# Something told us to continue, so we continue
|
||||
if '_continue' in data and data['_continue']:
|
||||
continue
|
||||
|
||||
# An error occurred so we bail out
|
||||
if '_error' in data and data['_error']:
|
||||
continue
|
||||
@ -1463,8 +1476,9 @@ class Schedule(object):
|
||||
|
||||
if data['_splay']:
|
||||
# The "splay" configuration has been already processed, just use it
|
||||
seconds = data['_splay'] - now
|
||||
seconds = (data['_splay'] - now).total_seconds()
|
||||
if 'when' in data:
|
||||
data['_next_fire_time'] = data['_splay']
|
||||
|
||||
if '_seconds' in data:
|
||||
if seconds <= 0:
|
||||
|
@ -872,3 +872,72 @@ class SchedulerEvalTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
ret = self.schedule.job_status(job_name)
|
||||
self.assertEqual(ret['_last_run'], run_time)
|
||||
self.assertEqual(ret['_next_fire_time'], next_run_time)
|
||||
|
||||
def test_eval_when_splay(self):
|
||||
'''
|
||||
verify that scheduled job runs
|
||||
'''
|
||||
job_name = 'test_eval_when_splay'
|
||||
splay = 300
|
||||
job = {
|
||||
'schedule': {
|
||||
job_name: {
|
||||
'function': 'test.ping',
|
||||
'when': '11/29/2017 4:00pm',
|
||||
'splay': splay
|
||||
}
|
||||
}
|
||||
}
|
||||
run_time1 = dateutil_parser.parse('11/29/2017 4:00pm')
|
||||
run_time2 = run_time1 + datetime.timedelta(seconds=splay)
|
||||
|
||||
# Add the job to the scheduler
|
||||
self.schedule.opts.update(job)
|
||||
|
||||
with patch('random.randint', MagicMock(return_value=splay)):
|
||||
# Evaluate to prime
|
||||
run_time = dateutil_parser.parse('11/29/2017 3:00pm')
|
||||
self.schedule.eval(now=run_time)
|
||||
ret = self.schedule.job_status(job_name)
|
||||
|
||||
# Evaluate at expected runtime1, should not run
|
||||
self.schedule.eval(now=run_time1)
|
||||
ret = self.schedule.job_status(job_name)
|
||||
self.assertNotIn('_last_run', ret)
|
||||
|
||||
# Evaluate at expected runtime2, should run
|
||||
self.schedule.eval(now=run_time2)
|
||||
ret = self.schedule.job_status(job_name)
|
||||
self.assertEqual(ret['_last_run'], run_time2)
|
||||
|
||||
def test_eval_when_splay_in_past(self):
|
||||
'''
|
||||
verify that scheduled job runs
|
||||
'''
|
||||
job_name = 'test_eval_when_splay_in_past'
|
||||
splay = 300
|
||||
job = {
|
||||
'schedule': {
|
||||
job_name: {
|
||||
'function': 'test.ping',
|
||||
'when': ['11/29/2017 6:00am'],
|
||||
'splay': splay
|
||||
}
|
||||
}
|
||||
}
|
||||
run_time1 = dateutil_parser.parse('11/29/2017 4:00pm')
|
||||
|
||||
# Add the job to the scheduler
|
||||
self.schedule.opts.update(job)
|
||||
|
||||
# Evaluate to prime
|
||||
run_time = dateutil_parser.parse('11/29/2017 3:00pm')
|
||||
self.schedule.eval(now=run_time)
|
||||
ret = self.schedule.job_status(job_name)
|
||||
|
||||
# Evaluate at expected runtime1, should not run
|
||||
# and _next_fire_time should be None
|
||||
self.schedule.eval(now=run_time1)
|
||||
ret = self.schedule.job_status(job_name)
|
||||
self.assertNotIn('_last_run', ret)
|
||||
self.assertEqual(ret['_next_fire_time'], None)
|
||||
|
Loading…
Reference in New Issue
Block a user