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

Skip a job #320

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Skip a job #320

wants to merge 1 commit into from

Conversation

chino540off
Copy link

As mentioned in #319, add the ability to skip a job without cancel it.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling cb6f020 on chino540off:master into 41f88b3 on dbader:master.

@SijmenHuizenga SijmenHuizenga linked an issue Mar 7, 2021 that may be closed by this pull request
@SijmenHuizenga SijmenHuizenga changed the title Issue #319: be able to skip a job Skip a job Mar 7, 2021
Copy link
Collaborator

@SijmenHuizenga SijmenHuizenga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this pr!

Just a few small comments left before we can merge 🚀.

Would you also be able to add an example to the docs?

@@ -73,6 +73,13 @@ class CancelJob(object):
pass


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's elaborate a bit more what it means to skip a job. We could mention that the job scheduling is not changed and that the job will run the next time run_pending is called (unless the job's deadline set by until is reached).

@@ -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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should self._schedule_next_run() also be included in the if statements body?

Comment on lines +493 to +494
if not isinstance(ret, SkipJob) and ret is not SkipJob:
self.last_run = datetime.datetime.now()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I would invert the if statement like so:

Suggested change
if not isinstance(ret, SkipJob) and ret is not SkipJob:
self.last_run = datetime.datetime.now()
if isinstance(ret, SkipJob) or ret is SkipJob:
return ret
self.last_run = datetime.datetime.now()

(untested suggestion)

That would make it more clear that returning SkipJob is a special flow. And the normal flow would continue on the same level.

if skip:
return schedule.SkipJob
else:
return None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice tests! I like them 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to skip a job
3 participants