Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to skip a job #319

Open
chino540off opened this issue Aug 6, 2019 · 3 comments · May be fixed by #320
Open

Ability to skip a job #319

chino540off opened this issue Aug 6, 2019 · 3 comments · May be fixed by #320

Comments

@chino540off
Copy link

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,

@WoLfulus
Copy link
Contributor

WoLfulus commented Aug 6, 2019

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

chino540off pushed a commit to chino540off/schedule that referenced this issue Aug 6, 2019
@chino540off chino540off linked a pull request Aug 6, 2019 that will close this issue
@chino540off
Copy link
Author

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.

@SijmenHuizenga
Copy link
Collaborator

SijmenHuizenga commented Mar 7, 2021

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:

ret = self.job_func()
self.last_run = datetime.datetime.now()
self._schedule_next_run()

Anyone willing to implement this and create a pr?

EDIT: Well well well, it turns out an pr is already open! See #320

@SijmenHuizenga SijmenHuizenga linked a pull request Mar 7, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants