本文介绍了如何正确配置djcelery结果后端到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我设置了:



<$

我正在尝试设置djangocelery以将任务结果存储在数据库中。 p $ p> CELERY_RESULT_BACKEND ='djcelery.backends.database.DatabaseBackend'

然后我同步并迁移了db(没有错误)。



芹菜正在工作,任务得到处理(我可以得到结果),但管理员显示没有任务。在数据库中有两个表 celery_taskmeta djcelery_taskmeta 。第一个是持有结果,第二个显示在管理员中。任何人都有洞察力如何正确配置?

解决方案

检查,当您使用djcelery时,设置 CELERY_RESULT_BACKEND =数据库或甚至不打扰写此行由于djcelery默认设置。



结果存储在 celery_taskmeta 表中,您应该注册 djcelery.models.TaskMeta 自己管理:

 #在某些管理员中。 py,它由`djcelery`在`INSTALLED_APPS` 
#或直接在djcelery / admin.py

从djcelery.models中导入TaskMeta
class TaskMetaAdmin( admin.ModelAdmin)
readonly_fields =('result',)
admin.site.register(TaskMeta,TaskMetaAdmin)


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?

解决方案

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)

这篇关于如何正确配置djcelery结果后端到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 19:02