Get progress from async python celery chain by chain id

北城余情 提交于 2019-12-05 02:43:38

Like @Hernantz said, you can't recover the parent chain from just the task ID, you'd have to iterate over your queue which may or may not be possible depending on what you use as a broker.

But if you have the last task id to do the lookup then you have the chain, you just need to store all the task ids and rebuild the chain when you need to examine their status. You can use the following functions:

def store(node):
    id_chain = []
    while node.parent:
      id_chain.append(node.id)
      node = node.parent
    id_chain.append(node.id)
    return id_chain

def restore(id_chain):
    id_chain.reverse()
    last_result = None
    for tid in id_chain:
        result = celery.AsyncResult(tid)
        result.parent = last_result
        last_result = result
    return last_result

Call store when you first get a AsyncResult from chain. Calling restore on that will give you a linked list of AsyncResults like chain gives you.

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