Job scheduling for humans.
Project description
Python job scheduling for humans. Run Python functions (or any other callable) periodically using a friendly syntax.
A simple to use API for scheduling jobs, made for humans.
In-process scheduler for periodic jobs. No extra processes needed!
Very lightweight and no external dependencies.
Excellent test coverage.
Usage
$ pip install precise-scheduler
import datetime
import precise_scheduler
import time
import pause
scheduler = precise_scheduler.Scheduler(schedule_base="last_schedule")
#scheduler = precise_scheduler.Scheduler(schedule_base="last_run_start")
#scheduler = precise_scheduler.Scheduler()
def greet(name):
print("Hello", name, datetime.datetime.now())
time.sleep(1)
scheduler.every(2).seconds.do(greet, name="Alice")
scheduler.every(4).seconds.do(greet, name="Bob")
from precise_scheduler import every, repeat
@repeat(scheduler.every(5).seconds, "World")
@repeat(scheduler.every().day, "Mars")
def hello(planet):
print("Hello", planet, datetime.datetime.now())
time.sleep(0.5)
while True:
pause.until(scheduler.get_next_run())
scheduler.run_pending()
# Hello Alice 2023-03-02 12:24:31.000249
# Hello Alice 2023-03-02 12:24:33.000094
# Hello Bob 2023-03-02 12:24:34.001463
# Hello World 2023-03-02 12:24:35.003073
# Hello Alice 2023-03-02 12:24:35.503961
# Hello Alice 2023-03-02 12:24:37.000157
# Hello Bob 2023-03-02 12:24:38.001703
# Hello Alice 2023-03-02 12:24:39.003366
# Hello World 2023-03-02 12:24:40.004778
# Hello Alice 2023-03-02 12:24:41.000172
Comparison with schedule
This test will show how the old module (schedule ) drifts from the schedule on each execution and the new version is accurate to the schedule.
The small microseconds shown in time is the time it takes to execute the print statement, call of function and slight difference of time.sleep(0.001) , which is common for both implementations
$ pip install precise-scheduler
$ pip install schedule
import datetime
import precise_scheduler
import time
import schedule
scheduler = precise_scheduler.Scheduler(schedule_base="last_schedule")
schedule_old = schedule.Scheduler()
def greet(name):
print("Hello", name, datetime.datetime.now())
time.sleep(1)
scheduler.every(3).seconds.do(greet, name="precise_scheduler")
schedule_old.every(3).seconds.do(greet, name="schedule")
while True:
time.sleep(0.001)
scheduler.run_pending()
schedule_old.run_pending()
# Hello precise_scheduler 2023-03-08 11:16:42.000479
# Hello schedule 2023-03-08 11:16:43.001039
# Hello precise_scheduler 2023-03-08 11:16:45.000918
# Hello schedule 2023-03-08 11:16:47.002968
# Hello precise_scheduler 2023-03-08 11:16:48.004551
# Hello precise_scheduler 2023-03-08 11:16:51.000129
# Hello schedule 2023-03-08 11:16:52.001413
Background
This package is a slight improvement of https://github.com/dbader/schedule
The changes are
Previously the calculation of next schedule was based on end of execution. Now you can also select based on start of last execution start or based on schedule (will be same unless you have a on demand execution).
All schedules will be truncated to 0 microseconds.
The code is updated to newer Pep requirements
The reason for starting this package is the above updates are really needed and the package has not being updated for long and is under MIT licence.
For now the documentation remains the same only difference is mentioned below in code example and you can check out examples folder for python files
Documentation
precise_scheduler’s documentation lives at precise_scheduler.readthedocs.io.
Meta
Bibin Varghese - @bibinvargheset - bibinvargheset@gmail.com
This package is a based on https://github.com/dbader/schedule
Inspired by Adam Wiggins’ article “Rethinking Cron” and the clockwork Ruby module.
Distributed under the MIT license. See LICENSE.txt for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file precise_scheduler-2.0.1b0.tar.gz
.
File metadata
- Download URL: precise_scheduler-2.0.1b0.tar.gz
- Upload date:
- Size: 21.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a0a629bcd45e9b29303073d76010a12bc71fd8f1cef922467722769a95be8d5 |
|
MD5 | 3c9811daa66f86d44d3d2d69ab96b6c4 |
|
BLAKE2b-256 | 3716c8f88eff5045e0a1e6688a97c3988d960d6e393aa0596465e243b6274cef |
File details
Details for the file precise_scheduler-2.0.1b0-py3-none-any.whl
.
File metadata
- Download URL: precise_scheduler-2.0.1b0-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bf4ad553329446cbd61cb69faddf04459107292838008fbf41b11e40f46610a |
|
MD5 | a6407f56f8b3396aaa7529e0bec3ce62 |
|
BLAKE2b-256 | 452fa75eb34357e9ae435d465ed20ea55461d0fe9e7918368a38a9f9f9cdf70e |