Skip to content
Permalink
Browse files

Merge cb6f020 into 41f88b3

  • Loading branch information
chino540off committed Aug 6, 2019
2 parents 41f88b3 + cb6f020 commit 7c8566449c72a7193e33274ec304e8f96a2266dc
Showing with 34 additions and 1 deletion.
  1. +9 −1 schedule/__init__.py
  2. +25 −0 test_schedule.py
@@ -73,6 +73,13 @@ class CancelJob(object):
pass


class SkipJob(object):
"""
Can be returned from a job to skip a run.
"""
pass


class Scheduler(object):
"""
Objects instantiated by the :class:`Scheduler <Scheduler>` are
@@ -483,7 +490,8 @@ def run(self):
"""
logger.info('Running job %s', self)
ret = self.job_func()
self.last_run = datetime.datetime.now()
if not isinstance(ret, SkipJob) and ret is not SkipJob:
self.last_run = datetime.datetime.now()
self._schedule_next_run()
return ret

@@ -444,6 +444,31 @@ def stop_job():
schedule.run_all()
assert len(schedule.jobs) == 0

def test_skip_job(self):
skip = True

def skip_job():
if skip:
return schedule.SkipJob
else:
return None

job = every().second.do(skip_job)

assert len(schedule.jobs) == 1
assert job.last_run is None

schedule.run_all()

assert len(schedule.jobs) == 1
assert job.last_run is None

skip = False
schedule.run_all()

assert len(schedule.jobs) == 1
assert job.last_run is not None

def test_tag_type_enforcement(self):
job1 = every().second.do(make_mock_job(name='job1'))
self.assertRaises(TypeError, job1.tag, {})

0 comments on commit 7c85664

Please sign in to comment.
You can’t perform that action at this time.