Search code examples
djangodjango-celery

How to remove celery task ?


I practice django-celery

settings.py

#import datetime
#CELERYBEAT_SCHEDULE = {
#    'hello_task': {
#        'task': 'hello_task',
#        'schedule': datetime.timedelta(seconds=20),
#    },
#}

import datetime
CELERYBEAT_SCHEDULE = {
    'add-every-30-seconds': {
        'task': 'app1.tasks.myfunc',
        'schedule': datetime.timedelta(seconds=30),
    },
}

I try hello_task schedule at first,then I commented it and try add-every-30-seconds

But it still want to execute when hello_task time comes

So I check the database and found it was save the record int it

enter image description here

Why wouldn't it delete when I commented it ?? Is there any command or normal way to delete it ???

Or If I just delete it from database is well ??


Solution

  • If you're using the django-celery database scheduler those periodic tasks in CELERYBEAT_SCHEDULE dict will be added to Django's database, as you found out. django-celery's scheduler then reads its settings primarily from the database. Removing entries from the dict just means that django-celery has nothing to add to the database.

    To delete the task properly, remove it from the Django admin page (Djcelery > Periodic Tasks).