Django Celery-缺少某些东西,但我不知道该怎么办?有结果但无法获得结果 [英] Django Celery - Missing something but I have no idea what? Have results but can't get them

查看:62
本文介绍了Django Celery-缺少某些东西,但我不知道该怎么办?有结果但无法获得结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务进入芹菜并得到结果。我知道这是因为我可以这样做。

My task goes into celery and gets results. I know this because I can do this.

>>> ts = TaskState.objects.all()[0]
>>> ts
Out[31]: <TaskState: SUCCESS apps.checklist.tasks.bulk_checklist_process(ec01461b-3431-478d-adfc-6d6cf162e9ad) ts:2012-07-20 14:35:41>
>>> ts.state
Out[32]: u'SUCCESS'
>>> ts.result
Out[33]: u'{\'info\': ["Great",]}'

但是当我尝试使用有据可查的获得结果的方法-所有地狱都会崩溃。

But when I attempt to use the documented way to get the result - all hell breaks loose..

>>> from celery.result import BaseAsyncResult
>>> result = BaseAsyncResult(ts.task_id)
>>> result.get()
../lib/python2.7/site-packages/djcelery/managers.py:178: TxIsolationWarning: Polling results with transaction isolation level repeatable-read within the same transaction may give outdated results. Be sure to commit the transaction for each poll iteration.
  "Polling results with transaction isolation level "

所以我有两个问题。


  1. 我的芹菜装置中缺少什么导致此错误。我显然有结果,但是BaseAsyncResult被抬高了。我什至不知道在哪里寻找?

  2. 只要我有 ts.state == SUCCESS ,它就会忽略1秒钟。 code>我可以使用 ts.result 运行。

  1. What am I missing in my setup of celery that is causing this error. I clearly have the results but BaseAsyncResult is jacked up. I don't even know where to look for this?
  2. Ignoring 1 for a sec it looks like as long as I have ts.state == SUCCESS I can just run with the ts.result. What would be the drawback to that and what format is that result in?

更新

因此第二部分很简单。 可怕但很容易。

So the second part is easy. Scary but easy..

context['results'] = resulting_values = result.get(propagate=False)
if not isinstance(resulting_values, dict):
    context['results'] = resulting_values = eval(context['task'].result)
    log.error("We should not be here..")


推荐答案

就在您粘贴的警告中:

TxIsolationWarning: Polling results with transaction isolation level repeatable-read 
within the same transaction may give outdated results. Be sure to commit the transaction   
for each poll iteration.

要使用数据库获取结果,以及是否要在同一过程中查询它们,请使用
,那么您要么需要将数据库的隔离级别配置为 READ-COMMITTED
,要么在检查结果之前提交事务。

To use the database for results, and if you want to poll for them in the same process then you either need to configure the isolation level of the database to be READ-COMMITTED or commit the transaction before you check for the result.

还不推荐使用 BaseAsyncResult ,请使用

from celery.result import AsyncResult

这篇关于Django Celery-缺少某些东西,但我不知道该怎么办?有结果但无法获得结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆