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

1.1.1 - deadline callback #486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ Thanks to all the wonderful folks who have contributed to schedule over the year
- ebllg <https://github.com/ebllg>
- fredthomsen <https://github.com/fredthomsen>
- biggerfisch <https://github.com/biggerfisch>
- sosolidkk <https://github.com/sosolidkk>
- sosolidkk <https://github.com/sosolidkk>
- stromajer <https://github.com/stromajer>
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
History
-------

1.1.1 (2021-09-17)
++++++++++++++++++
- Added deadline callback which may be optionally invoked before Job canceling

1.1.0 (2021-04-09)
++++++++++++++++++

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
# built documents.
#
# The short X.Y version.
version = u"1.1.0"
version = u"1.1.1"
# The full version, including alpha/beta/rc tags.
release = u"1.1.0"
release = u"1.1.1"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
19 changes: 19 additions & 0 deletions schedule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ def __init__(self, interval: int, scheduler: Scheduler = None):
self.tags: Set[Hashable] = set() # unique set of tags for the job
self.scheduler: Optional[Scheduler] = scheduler # scheduler to register with

self.d_callback = None

def __lt__(self, other) -> bool:
"""
PeriodicJobs are sortable based on the scheduled time they
Expand Down Expand Up @@ -611,6 +613,17 @@ def until(
)
return self

def deadline_callback(self, callback: Callable):
"""
Specifies optional callback function which will be invoked before Job cancelling.
Function will be called with canceling Job.

:param callback: The function to be invoked
:return: The invoked job instance
"""
self.d_callback = callback
return self

def do(self, job_func: Callable, *args, **kwargs):
"""
Specifies the job_func that should be called every time the
Expand Down Expand Up @@ -655,6 +668,9 @@ def run(self):
"""
if self._is_overdue(datetime.datetime.now()):
logger.debug("Cancelling job %s", self)
# run callback if defined
if self.d_callback:
self.d_callback(self)
return CancelJob

logger.debug("Running job %s", self)
Expand All @@ -664,6 +680,9 @@ def run(self):

if self._is_overdue(self.next_run):
logger.debug("Cancelling job %s", self)
# run callback if defined
if self.d_callback:
self.d_callback(self)
return CancelJob
return ret

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from setuptools import setup


SCHEDULE_VERSION = "1.1.0"
SCHEDULE_VERSION = "1.1.1"
SCHEDULE_DOWNLOAD_URL = "https://github.com/dbader/schedule/tarball/" + SCHEDULE_VERSION


Expand Down