Djcelery:如何将芹菜任务状态保存到数据库中

时间:2015-11-20 03:30:34

标签: python django celery

我的芹菜任务运行良好 但我发现我的djcelery_taskstate表没有任何内容:
enter image description here

如何将数据保存到其中?

这是我的设置:

settings.py

BROKER_URL = 'redis://localhost:6379'
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'  
CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend'
CELERY_TIMEZONE = 'Asia/Taipei'

celery.py

from __future__ import absolute_import
import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
from django.conf import settings  # noqa
app = Celery('myproject')

app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
app.conf.update(
    CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
    CELERY_TIMEZONE = 'Asia/Taipei'
)

tasks.py

from __future__ import absolute_import
from celery.task.schedules import crontab
from celery.decorators import periodic_task
from celery import task
from datetime import timedelta
from myapp.deal import check_data


@periodic_task(run_every=timedelta(seconds=30),name="collect-rawdata",ignore_result=True)
def rawdata():
    return check_data()

这是我运行芹菜的命令:

一个终端运行:

celery -A wiarea worker -l info

另一次运行:

celery -A wiarea beat -l info 

1 个答案:

答案 0 :(得分:0)

您已将ignore_result设为True。这使得Celery删除了结果,而不是将其保存在任何地方。