mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Updating skip_job and postpone_job to acceept date strings. Reverting skip_explicit and run_explicit to not be prefixed by an undercore.
This commit is contained in:
parent
cb68c12e7a
commit
29fea7c550
@ -966,7 +966,7 @@ def postpone_job(name,
|
||||
Postpone a job in the minion's schedule
|
||||
|
||||
Current time and new time should be in date string format,
|
||||
%Y-%m-%dT%H:%M:%S.
|
||||
default value is %Y-%m-%dT%H:%M:%S.
|
||||
|
||||
.. versionadded:: Oxygen
|
||||
|
||||
@ -1028,11 +1028,13 @@ def postpone_job(name,
|
||||
event_data = {'name': name,
|
||||
'time': current_time,
|
||||
'new_time': new_time,
|
||||
'time_fmt': time_fmt,
|
||||
'func': 'postpone_job'}
|
||||
elif name in list_(show_all=True, where='pillar', return_yaml=False):
|
||||
event_data = {'name': name,
|
||||
'time': current_time,
|
||||
'new_time': new_time,
|
||||
'time_fmt': time_fmt,
|
||||
'where': 'pillar',
|
||||
'func': 'postpone_job'}
|
||||
else:
|
||||
@ -1066,7 +1068,7 @@ def skip_job(name, current_time, **kwargs):
|
||||
Skip a job in the minion's schedule at specified time.
|
||||
|
||||
Time to skip should be specified as date string format,
|
||||
%Y-%m-%dT%H:%M:%S.
|
||||
default value is %Y-%m-%dT%H:%M:%S.
|
||||
|
||||
.. versionadded:: Oxygen
|
||||
|
||||
@ -1107,10 +1109,12 @@ def skip_job(name, current_time, **kwargs):
|
||||
if name in list_(show_all=True, where='opts', return_yaml=False):
|
||||
event_data = {'name': name,
|
||||
'time': current_time,
|
||||
'time_fmt': time_fmt,
|
||||
'func': 'skip_job'}
|
||||
elif name in list_(show_all=True, where='pillar', return_yaml=False):
|
||||
event_data = {'name': name,
|
||||
'time': current_time,
|
||||
'time_fmt': time_fmt,
|
||||
'where': 'pillar',
|
||||
'func': 'skip_job'}
|
||||
else:
|
||||
|
@ -486,16 +486,19 @@ class Schedule(object):
|
||||
'''
|
||||
time = data['time']
|
||||
new_time = data['new_time']
|
||||
time_fmt = data.get('time_fmt', '%Y-%m-%dT%H:%M:%S')
|
||||
|
||||
# ensure job exists, then disable it
|
||||
if name in self.opts['schedule']:
|
||||
if '_skip_explicit' not in self.opts['schedule'][name]:
|
||||
self.opts['schedule'][name]['_skip_explicit'] = []
|
||||
self.opts['schedule'][name]['_skip_explicit'].append(time)
|
||||
if 'skip_explicit' not in self.opts['schedule'][name]:
|
||||
self.opts['schedule'][name]['skip_explicit'] = []
|
||||
self.opts['schedule'][name]['skip_explicit'].append({'time': time,
|
||||
'time_fmt': time_fmt})
|
||||
|
||||
if '_run_explicit' not in self.opts['schedule'][name]:
|
||||
self.opts['schedule'][name]['_run_explicit'] = []
|
||||
self.opts['schedule'][name]['_run_explicit'].append(new_time)
|
||||
if 'run_explicit' not in self.opts['schedule'][name]:
|
||||
self.opts['schedule'][name]['run_explicit'] = []
|
||||
self.opts['schedule'][name]['run_explicit'].append({'time': new_time,
|
||||
'time_fmt': time_fmt})
|
||||
|
||||
elif name in self._get_schedule(include_opts=False):
|
||||
log.warning("Cannot modify job %s, it's in the pillar!", name)
|
||||
@ -512,12 +515,14 @@ class Schedule(object):
|
||||
Ignores jobs from pillar
|
||||
'''
|
||||
time = data['time']
|
||||
time_fmt = data.get('time_fmt', '%Y-%m-%dT%H:%M:%S')
|
||||
|
||||
# ensure job exists, then disable it
|
||||
if name in self.opts['schedule']:
|
||||
if '_skip_explicit' not in self.opts['schedule'][name]:
|
||||
self.opts['schedule'][name]['_skip_explicit'] = []
|
||||
self.opts['schedule'][name]['_skip_explicit'].append(time)
|
||||
if 'skip_explicit' not in self.opts['schedule'][name]:
|
||||
self.opts['schedule'][name]['skip_explicit'] = []
|
||||
self.opts['schedule'][name]['skip_explicit'].append({'time': time,
|
||||
'time_fmt': time_fmt})
|
||||
|
||||
elif name in self._get_schedule(include_opts=False):
|
||||
log.warning("Cannot modify job %s, it's in the pillar!", name)
|
||||
@ -813,7 +818,6 @@ class Schedule(object):
|
||||
'skip_during_range']
|
||||
for job, data in six.iteritems(schedule):
|
||||
|
||||
log.debug('=== job %s data %s ===', job, data)
|
||||
# Clear out _skip_reason from previous runs
|
||||
if '_skip_reason' in data:
|
||||
del data['_skip_reason']
|
||||
@ -889,11 +893,11 @@ class Schedule(object):
|
||||
)
|
||||
continue
|
||||
|
||||
if '_run_explicit' in data:
|
||||
if 'run_explicit' in data:
|
||||
_run_explicit = []
|
||||
for _run_time in data['_run_explicit']:
|
||||
_run_explicit.append(datetime.datetime.strptime(_run_time,
|
||||
'%Y-%m-%dT%H:%M:%S'))
|
||||
for _run_time in data['run_explicit']:
|
||||
_run_explicit.append(datetime.datetime.strptime(_run_time['time'],
|
||||
_run_time['time_fmt']))
|
||||
|
||||
if isinstance(_run_explicit, six.integer_types):
|
||||
_run_explicit = [_run_explicit]
|
||||
@ -1241,13 +1245,14 @@ class Schedule(object):
|
||||
# after the skip_during_range is over
|
||||
if 'run_after_skip_range' in data and \
|
||||
data['run_after_skip_range']:
|
||||
if '_run_explicit' not in data:
|
||||
data['_run_explicit'] = []
|
||||
if 'run_explicit' not in data:
|
||||
data['run_explicit'] = []
|
||||
# Add a run_explicit for immediately after the
|
||||
# skip_during_range ends
|
||||
_run_immediate = (end + datetime.timedelta(seconds=self.opts['loop_interval'])).strftime('%Y-%m-%dT%H:%M:%S')
|
||||
if _run_immediate not in data['_run_explicit']:
|
||||
data['_run_explicit'].append(_run_immediate)
|
||||
if _run_immediate not in data['run_explicit']:
|
||||
data['run_explicit'].append({'time': _run_immediate,
|
||||
'time_fmt': '%Y-%m-%dT%H:%M:%S'})
|
||||
|
||||
if end > start:
|
||||
if start <= now <= end:
|
||||
@ -1276,11 +1281,11 @@ class Schedule(object):
|
||||
)
|
||||
continue
|
||||
|
||||
if '_skip_explicit' in data:
|
||||
if 'skip_explicit' in data:
|
||||
_skip_explicit = []
|
||||
for _skip_time in data['_skip_explicit']:
|
||||
_skip_explicit.append(datetime.datetime.strptime(_skip_time,
|
||||
'%Y-%m-%dT%H:%M:%S'))
|
||||
for _skip_time in data['skip_explicit']:
|
||||
_skip_explicit.append(datetime.datetime.strptime(_skip_time['time'],
|
||||
_skip_time['time_fmt']))
|
||||
if isinstance(_skip_explicit, six.string_types):
|
||||
_skip_explicit = [_skip_explicit]
|
||||
|
||||
|
@ -64,7 +64,8 @@ class SchedulerSkipTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
self.schedule.opts.update(job)
|
||||
|
||||
run_time = dateutil_parser.parse('11/29/2017 4:00pm')
|
||||
self.schedule.skip_job('job1', {'time': run_time.strftime('%Y-%m-%dT%H:%M:%S')})
|
||||
self.schedule.skip_job('job1', {'time': run_time.strftime('%Y-%m-%dT%H:%M:%S'),
|
||||
'time_fmt': '%Y-%m-%dT%H:%M:%S'})
|
||||
|
||||
# Run 11/29/2017 at 4pm
|
||||
self.schedule.eval(now=run_time)
|
||||
|
Loading…
Reference in New Issue
Block a user