跳转到主要内容

Django中异步Dramatiq任务的Cron风格调度器。

项目描述

Dramatiq Crontab

dramtiq-crontab logo: person in front of a schedule

Django中异步Dramatiq任务的Cron风格调度器。

  • 通过crontab语法设置重复任务
  • 基于强大的工具如DramatiqAPScheduler构建的轻量级辅助工具
  • Sentry cron监控支持

PyPi Version Test Coverage GitHub License

设置

您需要安装并正确设置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 (6.5 kB 查看哈希值)

上传时间

构建分布

dramatiq_crontab-1.0.7-py3-none-any.whl (8.1 kB 查看哈希值)

上传时间 Python 3

支持者

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF 赞助商PingdomPingdom监控SentrySentry错误日志StatusPageStatusPage状态页面