Django Celery - Missing something but I have no idea what? Have results but can't get them

一世执手 提交于 2019-12-13 03:18:56

问题


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 "

So I have two questions.

  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?

Update

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..")

回答1:


It says so right in the warning you pasted:

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.

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.

Also BaseAsyncResult is deprecated, please use

from celery.result import AsyncResult


来源:https://stackoverflow.com/questions/11587558/django-celery-missing-something-but-i-have-no-idea-what-have-results-but-can

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!