[英]Celery chain task use case?
Suppose functions a, b, ..., that must be run sequentially. 假设必须依次运行函数a,b,...。 We can make a task that does that:
我们可以执行以下任务:
def a(...):
...
def b(...):
...
...
@app.task
def abc(...):
a(...)
b(...)
...
Alternatively, we can make them separate tasks: 另外,我们可以将它们单独设置为任务:
@app.task
def a(...):
...
@app.task
def b(...):
...
...
and chain them: 并将它们链接:
@app.task
def abc(...):
chain(a.s(...), b.s(...), ...)
...
The first version is faster that the second (maybe not by much, depends on the task overhead vs. the average time spent in a, b, ...). 第一个版本比第二个版本快(可能不是很多,取决于任务开销与a,b,...中花费的平均时间)。 I suppose there must be a reason for
chain
but I haven't figured it out. 我想一定有一个
chain
的原因,但我还没有弄清楚。
There are several use cases: 有几种用例:
The list can go on, but I've definitely used all three in production environments. 清单可以继续,但是我肯定在生产环境中使用了这三个。 Good luck!
祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.