Django中异步Dramatiq任务的Cron风格调度器。
项目描述
Dramatiq Crontab
Django中异步Dramatiq任务的Cron风格调度器。
- 通过crontab语法设置重复任务
- 基于强大的工具如Dramatiq和APScheduler构建的轻量级辅助工具
- Sentry cron监控支持
设置
您需要安装并正确设置Dramatiq。
python3 -m pip install dramatiq-crontab
# or
python3 -m pip install dramatiq-crontab[sentry] # with sentry cron monitor support
将 dramatiq_crontab
添加到您的 settings.py
文件中的 INSTALLED_APPS
。
# settings.py
INSTALLED_APPS = [
'dramatiq_crontab',
# ...
]
最后,您需要在单独的进程中启动调度程序。
python3 manage.py crontab
设置 Redis 作为锁后端(可选)
如果您使用 Redis 作为代理,您也可以使用 Redis 作为锁后端。锁后端用于防止多个调度程序实例同时运行。如果您有多个应用程序实例运行,这非常重要。
# settings.py
DRAMATIQ_CRONTAB = {
"REDIS_URL": "redis://localhost:6379/0",
}
用法
# 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 监视器
如果您使用 Sentry,您可以将 cron 监视器添加到您的任务中。监视器的 slug 将是操作者的名称。例如,上面的例子中的 my_task
。
crontab 命令
$ 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.
项目详情
关闭
dramatiq_crontab-1.0.7.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a37810fb899f8f31e47bc5ce50fc50acbe98c2d3542984532d2f53b2c865d6ca |
|
MD5 | c6bfd62cc44919d8682e929f94da34c3 |
|
BLAKE2b-256 | 2b9895f3fd386f546bb6bb08da2a7c47aefa79a0c03c7c72b862da0e7fd06fbd |
关闭
dramatiq_crontab-1.0.7-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 994b606e47be23e5b5049fb05776001bb1c099600a8400f91709b638887efef2 |
|
MD5 | b92ef27afacfd1f21d465e13c737ae05 |
|
BLAKE2b-256 | c96c419101b1791c949850465cd8d9c5e0aeec40f85112f3557ccd49a422b83e |