简体   繁体   中英

Celery task not registering in django database

I am working on celery beat task and task is working fine (running properly on scheduled time) but i am not able to see task in my admin page and all celery related tables are empty in my PostgreSQL database (ex django_celery_beat_periodictask)

what i am missing here ??

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

celery -A drive worker -B --loglevel=debug -S django

You need to import app in proj/proj/__init__.py module. This ensures that the app is loaded when Django starts.

__init__.py

from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app

__all__ = ['celery_app']

docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM