从Celery获取最新的任务,并使用Django显示它们 [英] Getting latest tasks from Celery and display them using Django
问题描述
我可以使用简单的
result = status.tasks.mymethod.delay(参数)
提交作业,所有任务执行正常: p> [2013-09-30 17:04:11,369:INFO / MainProcess]获取经纪人的任务:status.tasks.prova [a22bf0b9 -0d5b-4ce5-967a-750f679f40be]
[2013-09-30 17:04:11,566:INFO / MainProcess]任务status.tasks.mymethod [a22bf0b9-0d5b-4ce5-967a-750f679f40be]成功了0.194540023804s :u'Done'
我想在一个页面中显示最近提交的10个作业及其状态。 Django有没有办法得到这样的对象?我在数据库中看到几张表( celery_taskmeta
和 celery_taskmeta_2ff6b945
),并尝试了一些访问对象,但Django始终显示一个 AttributeError
从Django访问Celery结果的正确方法是什么?
执行
cel = celery.status.tasks.get(None)
cel = status.tasks.all()
不起作用,导致上述AttributeError。 (状态
是我的应用程序的名称)
编辑:我确定保存任务,如这个小教程说:
默认情况下,django-celery将此状态存储在Django数据库中。您可以考虑选择替代结果后端或禁用状态(请参阅结果后端)。
遵循链接后,仅提供有关如何设置数据库连接的参考,而不是如何检索结果
尝试这样:
from djcelery.models import TaskMeta
TaskMeta.objects.all()
I have a Django 1.5.1 webapp using Celery 3.0.23 with RabbitMQ 3.1.5. and sqlite3.
I can submit jobs using a simple result = status.tasks.mymethod.delay(parameter)
, all tasks executes correctly:
[2013-09-30 17:04:11,369: INFO/MainProcess] Got task from broker: status.tasks.prova[a22bf0b9-0d5b-4ce5-967a-750f679f40be]
[2013-09-30 17:04:11,566: INFO/MainProcess] Task status.tasks.mymethod[a22bf0b9-0d5b-4ce5-967a-750f679f40be] succeeded in 0.194540023804s: u'Done'
I want to display in a page the latest 10 jobs submitted and their status. Is there a way in Django to get such objects? I see a couple of tables in the database (celery_taskmeta
and celery_taskmeta_2ff6b945
) and tried some accesses to the objects but Django always displays a AttributeError
page.
What is the correct way to access Celery results from Django?
Doing
cel = celery.status.tasks.get(None)
cel = status.tasks.all()
does not work, resulting in the aforementioned AttributeError. (status
is the name of my app)
EDIT: I am sure tasks are saved, as this small tutorial says:
By default django-celery stores this state in the Django database. You may consider choosing an alternate result backend or disabling states alltogether (see Result Backends).
Following the links there are only references on how to setup the DB connection and not how to retrieve the results.
Try this:
from djcelery.models import TaskMeta
TaskMeta.objects.all()
这篇关于从Celery获取最新的任务,并使用Django显示它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!