Ability to skip a job
Hi,
I'm creating a pool of tasks which can be run or not (depending on the weather). I would like to skip a particular run of a job without lost history of previous run.
I was thinking to do it like that.
def func():
# this time, the job should not be done,
# but must stay in the schedule queue for next time
# This must keep last_time property unchanged,
# and update next_time property
if something():
return schedule.SkipJob
# normal running
do_something_else()
schedule.every().day.do(func)
What do you think?
Cheers,
I'd prefer some kind of .validate(check_wether) on job definition. Which avoids putting the check inside the job itself.
I think you are right. But in order to respect the way of implementation (CancelJob), I did it like that.
Don't know what the maintainer think about it.
I like this idea! To summarize: A job that returns schedule.SkipJob should not be rescheduled. So last_run should not be update and _schedule_next_run should not be called.
We can implement this in the Job.run() method, right about here:
https://github.com/dbader/schedule/blob/0bab53ea7f3b143d16888b54dc3bd43089450da9/schedule/init.py#L661-L663
~Anyone willing to implement this and create a pr?~
EDIT: Well well well, it turns out an pr is already open! See #320