https://github.com/kbr/autocron
Web-framework independent asynchronous task manager for delayed/cron-tasks with no dependencies beside the standard-library. Successor of autotask.
https://github.com/kbr/autocron
asynchronous-task-queue cronjob-scheduler python
Last synced: 2 months ago
JSON representation
Web-framework independent asynchronous task manager for delayed/cron-tasks with no dependencies beside the standard-library. Successor of autotask.
- Host: GitHub
- URL: https://github.com/kbr/autocron
- Owner: kbr
- License: mit
- Created: 2023-11-19T12:45:34.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-20T14:42:58.000Z (12 months ago)
- Last Synced: 2025-06-01T00:02:34.713Z (4 months ago)
- Topics: asynchronous-task-queue, cronjob-scheduler, python
- Language: Python
- Homepage:
- Size: 300 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# autocron

**autocron** is a Python background task library with no dependencies beside the standard library. It works out of the box with webframeworks like django, pyramid, flask, bottle, tornado or starlette.
**autocron** makes it easy to delegate long running and recurring tasks to external processes. No hassle with configuration-files.
**autocron** is designed for the vast majority of webapplications that don't need massive scaling. And don't want to add unnecessary dependencies.
## Installation
For installation use pip:
```
$ pip install autocron
```or conda:
```
$ conda install autocron
```## Quickstart
autocron provides two decorators: ``cron`` that takes a string in [cron](https://en.wikipedia.org/wiki/Cron#CRON_expression)-format as argument, but accepts also keyword-arguments like *minutes* and *hours*. And ``delay`` to delegate a long running task to a background process.
Here is a simple example how to use autocron with the flask web-framework that can be run with ``$ flask --app application run``:
```
# application.pyimport autocron
from flask import Flaskapp = Flask(__name__)
autocron.start("the_flask_app.db", workers=2)@autocron.cron("* * * * *")
def cronjob():
# do something from time to time ...@autocron.delay
def do_this_later():
# time consuming task here ...@app.route("/later")
def later():
do_this_later()
return "delayed action triggered"
```After creating the flask ``app`` instance calling ``autocron.start()`` starts the background workers. The ``workers`` argument is optional and defaults to 1. The ``cron`` decorated ``cronjob()`` function will get executed every minute and the ``delay`` decorated ``do_this_later()`` function gets delegated to the background worker every time the application processes the ``/later`` url. Terminating the application will shut down the worker processes.
More information and examples how to use autocron with other frameworks are at the documentation.
## Documentation
The full documentation and release notes are at [https://autocron.readthedocs.org](https://autocron.readthedocs.org)