首页 文章

芹菜任务没有在django数据库中注册

提问于
浏览
2

我正在研究celery beat任务和 task is working fine (running properly on scheduled time) 但我无法在我的管理页面中看到任务,所有芹菜相关表在我的PostgreSQL数据库中都是空的(来自django_celery_beat_periodictask)

我在这里失踪了什么?

Requirement

Django==1.9.7
python==3.5
celery==4.1.0
django-celery-beat==1.0.1

Project Tree

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()

Run Command Used

芹菜 - 驱动 Worker -B --loglevel = debug -S django

1 回答

  • 0

    您需要在proj / proj / __ init__.py模块中导入app . 这可以确保在Django启动时加载应用程序 .

    init.py

    from __future__ import absolute_import, unicode_literals
    from .celery import app as celery_app
    
    __all__ = ['celery_app']
    

    docs

相关问题