我已经开始在我的 Django Python 项目中使用 Celery 4.1 并且遇到了签名。
在documentation它说了以下内容:
You just learned how to call a task using the tasks delay method in the calling guide, and this is often all you need, but sometimes you may want to pass the signature of a task invocation to another process or as an argument to another function.
A signature() wraps the arguments, keyword arguments, and execution options of a single task invocation in a way such that it can be passed to functions or even serialized and sent across the wire.
虽然我看到它们在一些示例中使用,但我真的不知道何时以及为何使用它们,以及它们解决了哪些问题。 有人可以向外行人解释一下吗?
最佳答案
签名与链一起使用以创建工作流。 “.s”是“.signature”的缩写。当使用“.s”时,表示将前端任务的结果或返回值传递给下一个任务。 “签名”的对立面是“不可变签名”,其中每个任务都是独立的。 例如(签名):
res = chain(add.s(2,2), add.s(4), add.s(8))
res().get()
>> 16
示例(不可变签名):
res = chain(add.si(2,2)|add.si(4,4)|add.si(8,8))()
res.get()
>>16
res.parent.get()
>>8
res.parent.parent.get()
>>4
关于python - 为什么我们需要 Celery 中的签名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48098829/