【发布时间】:2014-11-03 15:44:54
【问题描述】:
我有一个主要的 celery(在 Django 中)任务,它调用了一个子任务prefetch:
@shared_task
def main():
...
tasks.prefetch.s().delay(x)
Prefetch本身调用了一些子任务:
@shared_task
def prefetch(x):
...
do_prefetch.s().delay(x)
在main 中,稍后在调用prefetch 之后,我执行了许多其他子任务来进行一些处理。这些子任务需要在prefetch 完成后执行。 Prefetch 本身需要一些时间,所以我不仅要在 prefetch 之后执行 process 任务,还要延迟 60 秒。 Process 任务不需要prefetch 的输出,它们只需要在它完成后运行。并且process 任务本身可以彼此并行运行。
@shared_task
def main():
...
tasks.prefetch.s().delay(x)
...
for i in range(10):
tasks.process.s().delay(i)
我看到 Celery 的画布命令应该可以满足我的需要,但我不知道如何设置任务。下面是正确的吗?链是简单地通过创建它们来执行还是需要显式地执行?我的倒计时参数是否在正确的位置并意味着正确的事情(在预取后 60 秒的任何时间执行此任务)?
prefetch = tasks.prefetch.s(x)
g = group(tasks.process.s(i, countdown=60) for i in range(10))
c = (prefetch | g)
c()
【问题讨论】:
标签: django celery django-celery