English 中文(简体)
A. 任务状态和django-celery
原标题:Task state and django-celery

我使用 d,并担负着这样的任务:

class TestTask(Task):
    name = "enabler.test_task"

    def run(self, **kw):
        debug_log("begin test task")
        time.sleep(5)
        debug_log("end test task")

    def on_success(self, retval, task_id, args, kwargs):
        debug_log("on success")

    def on_failure(self, retval, task_id, args, kwargs):
        debug_log("on failure")

我利用Django炮弹执行任务:

python manage.py shell

r = tasks.TestTask().delay()

从表象中可以看出,任务已经执行:

[2012-01-16 08:13:29,362: INFO/MainProcess] Got task from broker: enabler.test_task[e2360811-d003-45bc-bbf8-c6fd5692c32c]
[2012-01-16 08:13:29,390: DEBUG/PoolWorker-3] begin test task
[2012-01-16 08:13:34,389: DEBUG/PoolWorker-3] end test task
[2012-01-16 08:13:34,390: DEBUG/PoolWorker-3] on success
[2012-01-16 08:13:34,390: INFO/MainProcess] Task enabler.test_task[e2360811-d003-45bc-bbf8-c6fd5692c32c] succeeded in 5.00004410744s: None

然而,当我从伤口中检查任务时,我总是去除:

>>> r = tasks.TestTask().delay()
>>> r
<AsyncResult: e2360811-d003-45bc-bbf8-c6fd5692c32c>
>>> r.state
 PENDING 
>>> r.state
 PENDING 
>>> r.state
 PENDING 
>>> r.state
 PENDING 

尽管任务得到了很好的执行。

为什么发生这种情况?

问题回答

你们使用哪种ery子? 我注意到,我确实很晚才来到该方,但是如果这样做,今后会帮助某人。 如果要忽略“结果”(这是最新版本的缺省)的任务,那么它就将停留在快车上,而不是站在站式车上。

他们在这里的文件

@celery.task(ignore_result=True)
def mytask(...)
    something()

您可以查看,如果有任何其他问题,请让我了解。

** 本文件迟交。 还有一个说明,即使你忽视了你真心实意的结果,也总是能够用人工方式更新国家。

from celery import current_task
current_task.update_state(state= PROGRESS , meta={ description :  Doing some task ,  current : 59,  tota : 73})

某些这种性质对于进步的障碍——也见于书记。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签