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.7.tar.gz
.
File metadata
- Download URL: dramatiq_crontab-1.0.7.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a37810fb899f8f31e47bc5ce50fc50acbe98c2d3542984532d2f53b2c865d6ca |
|
MD5 | c6bfd62cc44919d8682e929f94da34c3 |
|
BLAKE2b-256 | 2b9895f3fd386f546bb6bb08da2a7c47aefa79a0c03c7c72b862da0e7fd06fbd |
File details
Details for the file dramatiq_crontab-1.0.7-py3-none-any.whl
.
File metadata
- Download URL: dramatiq_crontab-1.0.7-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 994b606e47be23e5b5049fb05776001bb1c099600a8400f91709b638887efef2 |
|
MD5 | b92ef27afacfd1f21d465e13c737ae05 |
|
BLAKE2b-256 | c96c419101b1791c949850465cd8d9c5e0aeec40f85112f3557ccd49a422b83e |