-
-
Save ask/1040634 to your computer and use it in GitHub Desktop.
Get async celery results from subtasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tasks import task1 | |
from celery.task import TaskSet | |
from celery.result import AsyncResult, ResultSet | |
def get_results(queries): | |
query_procs = task1.delay(queries).get().join() | |
results = [] | |
for query_proc in query_procs: | |
results.extend(query_proc.join()) | |
return results | |
get_results(['a','b','c']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from celery.task import task, TaskSet | |
@task | |
def task1(queries): | |
return TaskSet(task2.subtask((query, )) for query in queries).apply_async() | |
@task | |
def task2(query): | |
return TaskSet(task3.subtask() for _ in xrange(20).apply_async() | |
@task | |
def task3() | |
time.sleep(2) | |
return 'done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment