How to properly configure djcelery results backend to database
Asked Answered
B

3

10

I'm trying to setup djangocelery to store task results in the databse.

I set:

CELERY_RESULT_BACKEND = 'djcelery.backends.database.DatabaseBackend'

then I synced and migrated the db (no errors).

Celery is working and tasks get processed (I can get the results), but admin shows there is no tasks. In the database are two tables celery_taskmeta and djcelery_taskmeta. First one is holding the results and second one is displayed in admin. Anyone has insight how to configure it properly?

Buchmanism answered 20/5, 2012 at 11:25 Comment(1)
possible duplicate of Monitoring Celery, what should I use?Buchmanism
J
19

Check the doc, when you use djcelery, set CELERY_RESULT_BACKEND="database" or don't even bother to write this line because djcelery sets it by default.

The result is stored in celery_taskmeta table, you should register djcelery.models.TaskMeta to admin by yourself:

# in some admin.py, which is contained by an app after `djcelery` in `INSTALLED_APPS`
# or directly in djcelery/admin.py

from djcelery.models import TaskMeta
class TaskMetaAdmin(admin.ModelAdmin):
    readonly_fields = ('result',)    
admin.site.register(TaskMeta, TaskMetaAdmin)
Jaredjarek answered 20/5, 2012 at 13:48 Comment(3)
I changed CELERY_RESULT_BACKEND to "database" but still id doesn't work.I have TaskState table in admin in application djcelery, and other models from that app registered in the admin are working --- worker model shows connected workers.Buchmanism
TaskState is for monitoring: docs.celeryproject.org/en/latest/userguide/…Gar
Also note that monitoring does not work for all brokers. Only those that have 'fanout' support in this table does: kombu.readthedocs.org/en/latest/…Gar
C
10

Related question with right answer is here.

You should actually run

python manage.py celery worker -E

and

python manage.py celerycam

After that tasks results will be displayed in admin (Djcelery › Tasks)

Cymbre answered 3/8, 2013 at 8:11 Comment(0)
I
0

Moving the config update e.g.
app.conf.update(CELERY_RESULT_BACKEND='djcelery.backends.database.DatabaseBackend')

to the end of file celery.py did the trick for me .

Ingenuous answered 13/1, 2015 at 3:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.