我正在研究芹菜节拍任务,任务工作正常(在预定时间正常运行)但我无法在管理页面中看到任务,所有芹菜相关表格都是空的PostgreSQL数据库(ex django_celery_beat_periodictask)
我在这里失踪了什么?
要求
Django==1.9.7
python==3.5
celery==4.1.0
django-celery-beat==1.0.1
项目树
advocate
|
drive
|
-- celery.py
-- tasks.py
celery.py
from __future__ import absolute_import, unicode_literals
from celery import Celery
from celery.schedules import crontab
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'advocate.settings')
# app = Celery('drive', broker='redis://localhost:6379/0')
app = Celery('drive', broker='redis://localhost:6379/0', include=['drive.tasks'])
app.control.purge()
app.config_from_object('django.conf:settings', namespace='CELERY')
# crontab for test
app.conf.beat_schedule = {
'Emails-Every-Mon_Wed_Fri': {
'task': 'drive.tasks.weekly_task',
'schedule': crontab(minute='*/5'),
},
}
app.conf.timezone = 'UTC'
# Optional configuration, see the application user guide.
app.conf.update(
result_expires=3600,
)
app.autodiscover_tasks()
if __name__ == '__main__':
app.start()
运行命令
芹菜 - 驾驶员-B --loglevel = debug -S django
答案 0 :(得分:0)
您需要在proj / proj / __ init__.py模块中导入app。这可以确保在Django启动时加载应用程序。
<强> __初始化__。PY 强>
from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app
__all__ = ['celery_app']