schedule icon indicating copy to clipboard operation
schedule copied to clipboard

Ability to skip a job

Open chino540off opened this issue 6 years ago • 3 comments

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,

chino540off avatar Aug 06 '19 17:08 chino540off

I'd prefer some kind of .validate(check_wether) on job definition. Which avoids putting the check inside the job itself.

WoLfulus avatar Aug 06 '19 18:08 WoLfulus

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.

chino540off avatar Aug 08 '19 09:08 chino540off

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

SijmenHuizenga avatar Mar 07 '21 10:03 SijmenHuizenga