如何從任務中獲取任務的task_id值?這裏是我的代碼:芹菜 - 獲取當前任務的任務ID
from celery.decorators import task
from django.core.cache import cache
@task
def do_job(path):
"Performs an operation on a file"
# ... Code to perform the operation ...
cache.set(current_task_id, operation_results)
的想法是,當我創建任務的新實例,我檢索任務對象的task_id
。然後我使用任務ID來確定任務是否完成。 I 不要想要跟蹤path
值的任務,因爲文件在任務完成後「清理乾淨」,並且可能存在也可能不存在。
在上面的例子中,我將如何得到current_task_id
的值?
這是從Celery 2.2.0(請參閱下面的答案)已棄用。 – Simon 2011-11-16 06:47:33