Cron style scheduler for asynchronous Dramatiq tasks in Django.
Project description
Dramatiq Crontab
Cron style scheduler for asynchronous Dramatiq tasks in Django.
- setup recurring tasks via crontab syntax
- lightweight helpers build on robust tools like Dramatiq and APScheduler
- Sentry cron monitor support
Setup
You need to have Dramatiq installed and setup properly.
python3 -m pip install dramatiq-crontab
# or
python3 -m pip install dramatiq-crontab[sentry] # with sentry cron monitor support
Add dramatiq_crontab
to your INSTALLED_APPS
in settings.py
:
# settings.py
INSTALLED_APPS = [
'dramatiq_crontab',
# ...
]
Finally, you lauch the scheduler in a separate process:
python3 manage.py crontab
Setup Redis as a lock backend (optional)
If you use Redis as a broker, you can use Redis as a lock backend as well. The lock backend is used to prevent multiple instances of the scheduler from running at the same time. This is important if you have multiple instances of your application running.
# settings.py
DRAMATIQ_CRONTAB = {
"REDIS_URL": "redis://localhost:6379/0",
}
Usage
# tasks.py
import dramatiq
from dramatiq_crontab import cron
@cron("*/5 * * * *") # every 5 minutes
@dramatiq.actor
def my_task():
my_task.logger.info("Hello World")
Sentry Cron Monitors
If you use Sentry you can add cron monitors to your tasks.
The monitor's slug will be the actor's name. Like my_task
in the example above.
The crontab command
$ python3 manage.py crontab --help
usage: manage.py crontab [-h] [--no-task-loading] [--no-heartbeat] [--version] [-v {0,1,2,3}]
[--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color]
[--force-color] [--skip-checks]
Run dramatiq task scheduler for all tasks with the `cron` decorator.
options:
-h, --help show this help message and exit
--no-task-loading Don't load tasks from installed apps.
--no-heartbeat Don't start the heartbeat actor.
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 dramatiq_crontab-1.0.8.tar.gz
.
File metadata
- Download URL: dramatiq_crontab-1.0.8.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51bf3ef7d82ca1d4141ec0c617ceaa3bf2c2ae0eb57ec96eeff015495b102a90 |
|
MD5 | c1879c83655d15afe3687fbe764ab52e |
|
BLAKE2b-256 | 036db944fce3d144110e08d376dbe06a5362d307a2cae6ea0638cf6116e6fba4 |
File details
Details for the file dramatiq_crontab-1.0.8-py3-none-any.whl
.
File metadata
- Download URL: dramatiq_crontab-1.0.8-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | caa5e88f1dcb84ffddcf0754fbdcd59a1a155b91357231a063625a1464c7e810 |
|
MD5 | f4192297739c509948236f6108635b38 |
|
BLAKE2b-256 | 0bc5fff41038fd7f9e1ec118e7efe3ad6d666492f5462dc4472a1bf7d1c73944 |