From 0dcc492f0c2ecd6a22b6d9881a34ac5ea34cc550 Mon Sep 17 00:00:00 2001 From: Mikael Koli Date: Sat, 17 Sep 2022 19:28:05 +0300 Subject: [PATCH] docs: updated readme --- README.md | 134 ++++++++++++++++++++---------------------------------- 1 file changed, 50 insertions(+), 84 deletions(-) diff --git a/README.md b/README.md index a2a71ae3..540fa211 100644 --- a/README.md +++ b/README.md @@ -23,31 +23,11 @@ ## What is it? -Rocketry is a modern scheduling framework for Python -applications. It is simple, clean and extensive. It is -the automation engine that sets your Python programs alive. +Rocketry is a modern statement-based scheduling framework +for Python. It is simple, clean and extensive. +It is suitable for small and big projects. -The library is minimal on the surface but large -and highly customizable underneath. The syntax very clean: - -```python -from rocketry import Rocketry - -app = Rocketry() - -@app.task('daily') -def do_daily(): - ... - -if __name__ == '__main__': - app.run() -``` - -
-Dislike the string syntax? - -There is also a condition API which is almost -identical to the string syntax: +This is how it looks like: ```python from rocketry import Rocketry @@ -63,19 +43,11 @@ if __name__ == '__main__': app.run() ``` -
- - -Compared to alternatives, Rocketry has the most elegant syntax and is the most productive. -It offers more features than Crontab or APScheduler but is much -easier to work with than Airflow. It does not make assumptions of your project. - Core functionalities: -- Powerful scheduling syntax -- A lot of built-in scheduling options -- Task parallelization -- Task parametrization +- Powerful scheduling +- Concurrency (async, threading, multiprocess) +- Parametrization - Task pipelining - Modifiable session also in runtime - Async support @@ -86,6 +58,33 @@ Links: - Source code: https://github.com/Miksus/rocketry - Releases: https://pypi.org/project/rocketry/ +## Why Rocketry? + +Unlike the alternatives, Rocketry's scheduler is +statement-based. Rocketry natively supports the +same scheduling strategies as the other options, +including cron and task pipelining, but it can also be +arbitrarily extended using custom scheduling statements. + +Here is an example of custom conditions: + +```python +from rocketry.conds import daily, time_of_week +from pathlib import Path + +@app.cond() +def file_exists(file): + return Path(file).exists() + +@app.task(daily.after("08:00") & file_exists("myfile.csv")) +def do_work(): + ... +``` + +Rocketry is suitable for quick automation projects +and for larger scale applications. It does not make +assumptions of your project structure. + ## Installation Install Rocketry from [PyPI](https://pypi.org/project/rocketry/): @@ -102,27 +101,10 @@ Here are some more examples of what it can do. **Scheduling:** ```python -@app.task("every 10 seconds") -def do_continuously(): - ... - -@app.task("daily after 07:00") -def do_daily_after_seven(): - ... - -@app.task("hourly & time of day between 22:00 and 06:00") -def do_hourly_at_night(): - ... - -@app.task("(weekly on Monday | weekly on Saturday) & time of day after 10:00") -def do_twice_a_week_after_ten(): - ... -``` -
-Same with condition API - -```python -from rocketry.conds import every, daily, hourly, time_of_day, weekly +from rocketry.conds import every +from rocketry.conds import hourly, daily, weekly, +from rocketry.conds import time_of_day +from rocketry.conds import cron @app.task(every("10 seconds")) def do_continuously(): @@ -136,32 +118,16 @@ def do_daily_after_seven(): def do_hourly_at_night(): ... -@app.task((weekly.on("Monday") | weekly.on("Saturday")) & time_of_day.after("10:00")) +@app.task((weekly.on("Mon") | weekly.on("Sat")) & time_of_day.after("10:00")) def do_twice_a_week_after_ten(): ... -``` - -
- -**Pipelining tasks:** - -```python -from rocketry.args import Return - -@app.task("daily after 07:00") -def do_first(): - ... - return 'Hello World' - -@app.task("after task 'do_first'") -def do_second(arg=Return('do_first')): - # arg contains the value of the task do_first's return +@app.task(cron("* 2 * * *")) +def do_based_on_cron(): ... - return 'Hello Python' ``` -
-Same with condition API + +**Pipelining tasks:** ```python from rocketry.conds import daily, after_success @@ -173,31 +139,31 @@ def do_first(): return 'Hello World' @app.task(after_success(do_first)) -def do_second(arg=Return(do_first)): +def do_second(arg=Return('do_first')): # arg contains the value of the task do_first's return ... return 'Hello Python' ``` -
- **Parallelizing tasks:** ```python -@app.task("daily", execution="main") +from rocketry.conds import daily + +@app.task(daily, execution="main") def do_unparallel(): ... -@app.task("daily", execution="async") +@app.task(daily, execution="async") async def do_async(): ... -@app.task("daily", execution="thread") +@app.task(daily, execution="thread") def do_on_separate_thread(): ... -@app.task("daily", execution="process") +@app.task(daily, execution="process") def do_on_separate_process(): ... ```