为什么我的芹菜任务没有运行?

时间:2017-02-01 11:30:26

标签: django celery django-celery

我遵循本指南: 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会写在那里)我错在哪里?

2 个答案:

答案 0 :(得分:3)

通过

运行芹菜
celery -A hc worker -B -l info

答案 1 :(得分:0)

您必须运行命令python manage.py celery beat才能开始定期任务并查看结果。只有你可以在celery shell中看到芹菜任务的print语句结果,而不是普通的Django runserver shell。