30👍
Signature used together with chain to create a workflow. “.s” is the abbreviation of “.signature”. when use “.s”, means that the result or return value of the front task will be pass to the next one. The opposite of ‘signature’ is ‘immutable signature’, in which every task is independent.
for example(signature):
res = chain(add.s(2,2), add.s(4), add.s(8))
res().get()
>> 16
example(immutable signature):
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
11👍
You can think of signatures in Celery as placeholders for running tasks. For example, let’s say you wish to construct a complex workflow consisting of chords, groups and chains, and use it in a different piece of code. In this case, it would be easier to define various task signatures and place them in your workflow as neccessary:
def create_workflow():
return chord([sig_1, sig_2, chain([sig_3, sig_4])],
body=group([sig_5, sig_6]).set(queue=PRIORITY_QUEUE))
Where each signature in this example has been pre-defined, which can ,make a lot of difference should those signatures be complicated.
Then you can call create_workflow()
and apply delay()
to it whenever needed
- [Django]-What is the best AJAX library for Django?
- [Django]-Select DISTINCT individual columns in django?
- [Django]-How to dynamically compose an OR query filter in Django?