diff --git a/AUTHORS.rst b/AUTHORS.rst index 0d0620fd..b1bfe659 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -32,4 +32,5 @@ Thanks to all the wonderful folks who have contributed to schedule over the year - ebllg - fredthomsen - biggerfisch -- sosolidkk \ No newline at end of file +- sosolidkk +- stromajer \ No newline at end of file diff --git a/HISTORY.rst b/HISTORY.rst index a85a8ce0..9b522032 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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) ++++++++++++++++++ diff --git a/docs/conf.py b/docs/conf.py index e63cd0de..064c8d80 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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. diff --git a/schedule/__init__.py b/schedule/__init__.py index 83a95815..db79496a 100644 --- a/schedule/__init__.py +++ b/schedule/__init__.py @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/setup.py b/setup.py index 360da610..9ae58bf0 100644 --- a/setup.py +++ b/setup.py @@ -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