mrbox 为真,您可以重试直到结果准备好,但在文档中并不清楚,当您重试时,您必须传递 setid 和子任务元素,并且要恢复它,您必须使用 map 函数,下面有一个示例代码来解释我的意思。
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")