Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
SijmenHuizenga committed Feb 28, 2021
1 parent c57ac3a commit 45eda3e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/examples.rst
Expand Up @@ -220,6 +220,7 @@ Run a job until a certain time
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: python
import schedule
from datetime import datetime, timedelta, time
Expand Down
25 changes: 15 additions & 10 deletions schedule/__init__.py
Expand Up @@ -520,13 +520,15 @@ def until(
"""
Schedule job to run until the specified moment.
The job is canceled whenever the next run is calculated and it turns out the next run is after the until_time.
The job is also canceled right before it runs, if the current time is after until_time.
This latter case can happen when the the job was scheduled to run before until_time, but runs after until_time.
The job is canceled whenever the next run is calculated and it turns out the
next run is after the until_time. The job is also canceled right before it runs,
if the current time is after until_time. This latter case can happen when the
the job was scheduled to run before until_time, but runs after until_time.
If until_time is a moment in the past, ScheduleValueError is thrown.
:param until_time: A moment in the future representing the latest time a job can be run.
:param until_time: A moment in the future representing the latest time a job can
be run.
If only a time is supplied, the date is set to today.
The following formats are accepted:
* datetime.datetime
Expand Down Expand Up @@ -573,7 +575,8 @@ def until(
self.cancel_after = cancel_after
else:
raise TypeError(
"until() takes a string, datetime.datetime, datetime.timedelta, datetime.time parameter"
"until() takes a string, datetime.datetime, datetime.timedelta, "
"datetime.time parameter"
)
if self.cancel_after < datetime.datetime.now():
raise ScheduleValueError(
Expand Down Expand Up @@ -614,11 +617,13 @@ def should_run(self) -> bool:
def run(self):
"""
Run the job and immediately reschedule it.
If the job's deadline is reached (configured using .until()), the job is not run and CancelJob is returned immediately.
If the next scheduled run exceeds the job's deadline, CancelJob is returned after the execution.
In this latter case CancelJob takes priority over any other returned value.
If the job's deadline is reached (configured using .until()), the job is not
run and CancelJob is returned immediately. If the next scheduled run exceeds
the job's deadline, CancelJob is returned after the execution. In this latter
case CancelJob takes priority over any other returned value.
:return: The return value returned by the `job_func`, or CancelJob if the job's deadline is reached.
:return: The return value returned by the `job_func`, or CancelJob if the job's
deadline is reached.
"""
if self._is_overdue(datetime.datetime.now()):
logger.debug("Cancelling job %s", self)
Expand Down Expand Up @@ -713,7 +718,7 @@ def _is_overdue(self, when: datetime.datetime):
return self.cancel_after is not None and when > self.cancel_after

def _decode_datetimestr(
self, datetime_str: str, formats: list[str]
self, datetime_str: str, formats: List[str]
) -> Optional[datetime.datetime]:
for f in formats:
try:
Expand Down
4 changes: 1 addition & 3 deletions test_schedule.py
Expand Up @@ -265,9 +265,7 @@ def test_until_time(self):
self.assertRaises(
ScheduleValueError, every().day.until, datetime.timedelta(minutes=-1)
)
self.assertRaises(
ScheduleValueError, every().day.until, datetime.time(hour=5)
)
self.assertRaises(ScheduleValueError, every().day.until, datetime.time(hour=5))

# Unschedule job after next_run passes the deadline
schedule.clear()
Expand Down

0 comments on commit 45eda3e

Please sign in to comment.