- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我多次阅读了几页 Google 搜索结果,我对如何布局我的项目感到非常困惑。我已经设法让 Celerybeat 使用 periodic_task 装饰器工作,但那是 depreciated and is being removed .据我了解,the docs建议 CELERYBEAT_SCHEDULE 是替代品。我已经完全按照所示创建了一个文件,但还没有弄明白:
我发现很难找到在非 Django 项目中使用 Celery 的正确方法。
最佳答案
the docs 有点令人困惑让它看起来像你的 CELERYBEAT_SCHEDULE 是一个单独的文件。实际上,它是您应用程序(又名:Celery() 实例)配置中的一个条目 see it listed here .因此,无论您如何将配置放入您的应用程序,这就是它的去向。
有很多方法可以将配置放入应用程序中。如果您相信“Explicit is better than implicit”,那么您可能想要:
celeryconfig.py
导入celeryconfig
app.config_from_object(celeryconfig)
示例 celeryconfig.py 文件
from datetime import timedelta
BROKER_URL = "redis://redis.local:6379/0"
BROKER_TRANSPORT_OPTIONS = {'fanout_prefix': True, 'fanout_patterns': True, 'visibility_timeout': 480}
CELERY_RESULT_BACKEND = BROKER_URL
CELERYBEAT_SCHEDULE = {
'addrandom-to-16K-every-2-seconds': {
'task': 'celery_test.tasks.addrandom', # notice that the complete name is needed
'schedule': timedelta(seconds=2),
'args': (16000, 42)
},
}
CELERY_TIMEZONE = 'UTC'
尝试将其放入类似 beatschedule.py
的文件中,然后运行 celery -A beatschedule beat
将得到 AttributeError: 'module' object has no属性“ celery ”
我创建了 this project按照文档中的描述演示 Celerybeat 的运行情况。我相信它比单独阅读文档更好地展示了它是如何工作的。我还创建了 this Docker image使其尽可能简单地启动和运行。
关于python - CELERYBEAT_SCHEDULE 在你的项目中放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28834506/
我正在尝试在 Celery 中设置一个每 3 秒运行一次的虚拟任务,但到目前为止收效甚微。这是我得到的输出: 我已经按如下方式设置了 celery : 在settings.py中: from date
我有两个使用相同数据库的 Django 应用程序。既使用 celery 又拥有自己的CELERYBEAT_SCHEDULE。有没有办法区分哪些任务应该在适当的 celery worker 中运行?现在
我多次阅读了几页 Google 搜索结果,我对如何布局我的项目感到非常困惑。我已经设法让 Celerybeat 使用 periodic_task 装饰器工作,但那是 depreciated and i
我可以让它作为独立应用程序运行,但我无法让它在 Django 中运行。 这是独立的代码: from celery import Celery from celery.schedules import
我创建了一个 celery worker,它有一个以 5 秒时间间隔运行的单个 celerybeat 计划任务。如何在不停止 celery worker 的情况下动态添加另一个节拍任务? 例子 app
对于使用 django 的 celery 非常陌生,我看到它是通过两种方式完成的,但不确定这是偏好问题还是背后是否有特定目的。我正在使用最新版本的 celery 并尝试从 2.x 更新我们当前的代码库
在Celery docs ,设置任务计划的标准方法被记录为将计划硬编码到配置文件中。 但是,它也暗示这可以用自定义后端代替。我看到 Django 有一个动态的、数据库驱动的选项,但我正在使用一个简单的
我是一名优秀的程序员,十分优秀!