python - CELERYBEAT_SCHEDULE 中的任务未被处理

标签 python django celery django-celery

我正在尝试在 Celery 中设置一个每 3 秒运行一次的虚拟任务,但到目前为止收效甚微。这是我得到的输出:

enter image description here

我已经按如下方式设置了 celery :

settings.py中:

from datetime import timedelta

BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'UTC'
CELERY_IMPORTS = ("api.tasks")
CELERYBEAT_SCHEDULE = {
    'add_job': {
        'task': 'add_job',
        'schedule': timedelta(seconds=3),
        'args': (16, 16)
    },
}
CELERY_TIMEZONE = 'UTC'

celery.py中:

from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blogpodapi.settings')
app = Celery(
    'blogpodapi',
)

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

tasks.py

from celery.task import task

@task(name='add_job')
def add_job(x, y):
    r = x + y
    print "task arguments: {x}, {y}".format(x=x, y=y)
    print "task result: {r}".format(r=r)
    return r

我的设置方式有没有做错什么?

最佳答案

之所以回答是因为这是我在 CELERYBEAT_SCHEDULE 上搜索时的第一个结果。

它对我不起作用的原因是它应该是 CELERY_BEAT_SCHEDULE

关于python - CELERYBEAT_SCHEDULE 中的任务未被处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38774128/

相关文章:

python - 如何在 127.0.0.1 :8000? 上再次运行 django 项目没有主机的 pg_hba.conf 条目

python-2.7 - 如果任务成功完成,AsyncResult 返回 None

python - 在 celery 任务中设置 while 循环

python - 我如何使用python通过https下载pdf文件

python - 从 csv 文件中提取特定文本

php - moodle 有 django 选项吗?

redis - celery 以 redis 作为代理,结果后端使用了太多的 redis 连接

list - 测试列表是否共享 python 中的任何项目

python - 在Python中分配数据框中值的渐进计数

python - 即使我可以使用凭据进行 SSH,Fabric 也会要求输入密码