为什么我的芹菜任务不是运行?

Why my celery task is not running?

我正在遵循本指南: http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html

我的 proj.celery 文件:

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
from celery.schedules import crontab

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hc.settings')

app = Celery('hc')

app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()


@app.task
def debug_task(a):
    print a
app.conf.beat_schedule = {
    # Executes every Monday morning at 7:30 a.m.
    'debug-every-minute': {
        'task': 'tasks.debug_task',
        'schedule': crontab(),
        'args': ("BLa BLA BlA", ),
    },
}

此外,我已将定期任务添加到 /admin/django_celery_beat/

我知道在管理中同时使用 app.conf.beat_schedule 和 periodic_task 是没有意义的,但我没有看到

之后的预期条目
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

(我希望 Bla bla 会写在那个下面)我哪里错了?

您必须 运行 命令 python manage.py celery beat 才能启动周期性任务并查看结果。只有你可以在你的 celery shell 而不是普通的 Django 运行 服务器 shell.

中看到 celery 任务的打印语句结果

运行芹菜

celery -A hc worker -B -l info