jobqueue.py: move the check for job.interval types into Job.__init__

This commit is contained in:
Jannes Höke 2016-12-14 06:30:18 +01:00
parent 8ead72e3ef
commit c7cd379016

View file

@ -79,17 +79,9 @@ class JobQueue(object):
job.job_queue = self
if next_t is None:
interval = job.interval
next_t = job.interval
if isinstance(interval, Number):
next_t = interval
elif isinstance(interval, datetime.timedelta):
next_t = interval.total_seconds()
else:
raise ValueError("The interval argument should be of type datetime.timedelta,"
" int or float")
elif isinstance(next_t, datetime.datetime):
if isinstance(next_t, datetime.datetime):
next_t = next_t - datetime.datetime.now()
elif isinstance(next_t, datetime.time):
@ -274,6 +266,10 @@ class Job(object):
if interval is None and repeat:
raise ValueError("You must either set an interval or set 'repeat' to 'False'")
if not (isinstance(interval, Number) or isinstance(interval, datetime.timedelta)):
raise ValueError("The 'interval' argument must be of type 'datetime.timedelta',"
" 'int' or 'float'")
self.days = days
self.name = callback.__name__
self._remove = Event()