2011-07-05 4 views
6

두 개 이상의 다른 작업 결과에 의존하는 셀러리 작업을하고 싶습니다. 내가 Python+Celery: Chaining jobs?http://pypi.python.org/pypi/celery-tasktree을 들여다 보았지만, 태스크가 단지 하나의 의존 태스크를 가지고있는 경우에만 유용합니다.종속성 그래프로 셀러리 작업 실행

TaskSet에 대해 알고 있지만 TaskSetResult.ready()가 True가되면 즉시 콜백을 실행할 수있는 방법이없는 것 같습니다. 내가 지금 염두에두고있는 것은 TaskSetResult.ready()를 몇 밀리 초마다 폴링하고 그것이 True를 반환 할 때 콜백을 시작하는주기적인 태스크를 갖는 것이다.

제안 사항?

답변

2

mrbox가 true 인 경우 결과가 준비 될 때까지 다시 시도 할 수 있지만 다시 시도 할 때 재 시도 할 때 setid 및 하위 타스크 요소를 전달해야하며 복구하려면지도를 사용해야합니다. 함수 아래에는 샘플 코드가 나와 의미를 설명합니다.

http://docs.celeryproject.org/en/latest/userguide/canvas.html#the-primitives에서 : 당신이 원하는 효과를 달성하기 위해 소위 코드를 사용할 수 있습니다 (3.0 이상) 셀러리의 최신 버전에서

def run(self, setid=None, subtasks=None, **kwargs): 

    if not setid or not subtasks: 
     #Is the first time that I launch this task, I'm going to launch the subtasks 
     … 
     tasks = [] 
     for slice in slices: 
      tasks.append(uploadTrackSlice.subtask((slice,folder_name))) 

     job = TaskSet(tasks=tasks) 
     task_set_result = job.apply_async() 
     setid = task_set_result.taskset_id 
     subtasks = [result.task_id for result in task_set_result.subtasks] 
     self.retry(exc=Exception("Result not ready"), args=[setid,subtasks]) 

    #Is a retry than we just have to check the results   
    tasks_result = TaskSetResult(setid, map(AsyncResult,subtasks)) 
    if not tasks_result.ready(): 
     self.retry(exc=Exception("Result not ready"), args=[setid,subtasks]) 
    else:  
     if tasks_result.successful(): 
      return tasks_result.join() 
     else: 
      raise Exception("Some of the tasks was failing") 
2

당신은 MAX_RETRIES = 없음으로 docs- link

또는 사용할 수있는 재시 방법으로 수행 한 것에 s 번째 비슷한 작업을 수행 할 수 있습니다 IMHO - .ready '기본'작업 중 하나()가 false 인 경우, 당신이 할 수있는 '.'두 작업이 모두 완료 될 때까지 .retry() 메서드를 호출하십시오.

7

간단한 코드를

코드 프리미티브를 사용하면 그룹에 속한 모든 작업이 완료 될 때 호출 할 콜백을 추가 할 수 있습니다. 알고리즘은 종종 번이 필요합니다.

>>> from celery import chord 
>>> res = chord((add.s(i, i) for i in xrange(10)), xsum.s())() 
>>> res.get() 
90 

면책 조항 :에 곤란하게 평행하지 않은 나는 아직이 자신을 시도하지 않았습니다.