2013-04-30 2 views
8

각 작업 상태를 쿼리하여 작업 체인의 진행을 얻으려고합니다. 하지만 ID로 체인을 검색 할 때, 나는 다르게 동작하는 객체를 얻습니다. 레디 스에서 파이썬 2.7.3와 셀러리 3.0.19을 사용 체인 ID로 비동기 파이썬 셀러리 체인에서 진행하십시오.

ipython에서 quering

tasks.py
from celery import Celery 

celery = Celery('tasks') 
celery.config_from_object('celeryconfig') 

def unpack_chain(nodes): 
    while nodes.parent: 
     yield nodes.parent 
     nodes = nodes.parent 
    yield nodes 

@celery.task 
def add(num, num2): 
    return num + num2 
에서

...

In [43]: from celery import chain 
In [44]: from tasks import celery, add, unpack_chain 
In [45]: c = chain(add.s(3,3), add.s(10).set(countdown=100)) 
In [46]: m = c.apply_async() 
In [47]: a = celery.AsyncResult(m.id) 
In [48]: a == m 
Out[48]: True 
In [49]: a.id == m.id 
Out[49]: True 
In [50]: [t.status for t in list(unpack_chain(a))] 
Out[50]: ['PENDING'] 
In [51]: [t.status for t in list(unpack_chain(m))] 
Out[51]: ['PENDING', 'SUCCESS'] 

. 만약 50 & 51에서 볼 수 있듯이

celery.AsyncResult 의해 리턴 된 값은 원래 체인과 다르다.

어떻게 체인 ID로 원래 체인 작업 목록을 얻을 수 있습니까?

+1

celery.AsyncResult는 result.parent 포인터를 잃어버린 것처럼 보입니다. – Hernantz

+0

나는 이걸 가지고 어디든 가지고 있는지 알고 싶어합니다. 비슷한 일을하려고합니다. – MikeTheReader

+1

irc에 묻기도하고 github에서 티켓을 열어도 도움이 전혀 없습니다. 기본적으로 여전히 손상되었습니다. 운 좋게도, 나의 요구 사항은 체인으로 그룹화 된 일부 작업에 대한 체인의 글로벌 상태를 묻는 것을 허용했습니다. 다른 작업은 사소한 지연에 의해 체인에 "추가"됩니다 : mytask.s() .set (countdown = 980) .apply_async()':(더 어딘가에 있다면 알려주십시오.) – Hernantz

답변

8

마찬가지로 @Hernantz는 작업 ID만으로 부모 체인을 복구 할 수 없다고 말하면 대기열을 반복하여 브로커로 사용하는 것에 따라 가능하지 않을 수도 있습니다.

룩업을 할 마지막 작업 ID가있는 경우 체인이있는 경우 상태를 확인해야 할 때 모든 작업 ID를 저장하고 체인을 다시 만들어야합니다. 다음 기능을 사용할 수 있습니다.

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 

체인에서 처음으로 AsyncResult를 가져올 때 저장소를 호출합니다. 복원을 호출하면 체인과 같은 AsyncResult의 링크 된 목록이 제공됩니다.

관련 문제