10
我使用Django,芹菜,有任務是這樣的:任務狀態和Django的芹菜
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 shell來運行任務:
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
然而,當我從地獄檢查任務狀態,我總是得到PENDING:
>>> r = tasks.TestTask().delay()
>>> r
<AsyncResult: e2360811-d003-45bc-bbf8-c6fd5692c32c>
>>> r.state
'PENDING'
>>> r.state
'PENDING'
>>> r.state
'PENDING'
>>> r.state
'PENDING'
儘管任務執行得很好。
爲什麼會發生這種情況?
謝謝你,先生! – 2013-11-21 11:57:10