Cron-like task scheduler with overlap prevention and interval support
Project description
philiprehberger-task-scheduler
Cron-like task scheduler with overlap prevention and interval support.
Install
pip install philiprehberger-task-scheduler
Usage
Cron Scheduling
from philiprehberger_task_scheduler import Scheduler
scheduler = Scheduler()
@scheduler.cron("*/5 * * * *") # every 5 minutes
def check_health():
ping_server()
@scheduler.cron("0 9 * * 1-5", overlap=False) # weekdays at 9am
def daily_report():
generate_and_send_report()
scheduler.start() # blocks
Interval Scheduling
@scheduler.interval(seconds=30)
def poll_queue():
process_messages()
@scheduler.interval(minutes=5, overlap=False)
def sync_data():
pull_latest_data()
One-Shot Tasks
@scheduler.once(delay=10) # run once after 10 seconds
def startup_task():
warm_cache()
Background Mode
scheduler.start(background=True)
# ... your app continues running ...
scheduler.stop()
Programmatic API
scheduler.add("my-job", fn=my_function, cron="0 * * * *")
scheduler.add("poller", fn=poll, interval_seconds=60)
scheduler.remove("my-job")
Next Run Preview
for name, next_time in scheduler.next_runs():
print(f"{name}: next at {next_time}")
Cron Syntax
Standard 5-field cron expressions:
┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6, Mon-Sun)
│ │ │ │ │
* * * * *
Supports: *, ranges (1-5), lists (1,3,5), steps (*/5).
License
MIT
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philiprehberger_task_scheduler-0.1.0.tar.gz.
File metadata
- Download URL: philiprehberger_task_scheduler-0.1.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9219d6b96f7c80bdf8edd187759de6e76c5c55e4e9bf94d4194ec1b3c2610439
|
|
| MD5 |
7038e83912ae00b6dc0acb1052de61a4
|
|
| BLAKE2b-256 |
f95c75f4f64dd382a54af5b6cc21e9307e712ee1a044fd70d702a527f3ddea8b
|
File details
Details for the file philiprehberger_task_scheduler-0.1.0-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_task_scheduler-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81379e073c9fb1028dadb82008c48d3fdb4c389625148ea164f5c7c0d31cca59
|
|
| MD5 |
ddb928a9a0b4c4ab34223ccf11877715
|
|
| BLAKE2b-256 |
500eb13ae4ceabc650b98c7f006ae61b466164eb5d888051a28ca8a7592fa434
|