addding not_during_range to schedule

This commit is contained in:
Gareth J. Greenaway 2017-11-06 22:29:56 -07:00
parent 5c737100c4
commit 52c2366c23
No known key found for this signature in database
GPG Key ID: 10B62F8A7CAD7A41
2 changed files with 33 additions and 1 deletions

View File

@ -58,6 +58,7 @@ SCHEDULE_CONF = [
'return_config',
'return_kwargs',
'run_on_start'
'not_during_range',
]
@ -353,7 +354,7 @@ def build_schedule_item(name, **kwargs):
for item in ['range', 'when', 'once', 'once_fmt', 'cron',
'returner', 'after', 'return_config', 'return_kwargs',
'until', 'run_on_start']:
'until', 'run_on_start', 'not_during_range']:
if item in kwargs:
schedule[name][item] = kwargs[item]

View File

@ -1322,6 +1322,37 @@ class Schedule(object):
Ignoring job {0}.'.format(job))
continue
if 'not_during_range' in data:
if not _RANGE_SUPPORTED:
log.error('Missing python-dateutil. Ignoring job {0}'.format(job))
continue
else:
if isinstance(data['not_during_range'], dict):
try:
start = int(time.mktime(dateutil_parser.parse(data['not_during_range']['start']).timetuple()))
except ValueError:
log.error('Invalid date string for start in not_during_range. Ignoring job {0}.'.format(job))
continue
try:
end = int(time.mktime(dateutil_parser.parse(data['not_during_range']['end']).timetuple()))
except ValueError:
log.error('Invalid date string for end in not_during_range. Ignoring job {0}.'.format(job))
log.error(data)
continue
if end > start:
if start <= now <= end:
run = False
else:
run = True
else:
log.error('schedule.handle_func: Invalid range, end must be larger than start. \
Ignoring job {0}.'.format(job))
continue
else:
log.error('schedule.handle_func: Invalid, range must be specified as a dictionary. \
Ignoring job {0}.'.format(job))
continue
if not run:
continue