This is only a simple note, Group,chord and other content to read the document directly
Subtask is actually a signature that can be passed around
One usage of raw is:
>>> from celery import signature
>>> signature (' Tasks.add ', args= (2, 2), countdown=10)
Tasks.add (2, 2)
Official usage:
>>> Add.subtask ((2, 2), countdown=10)
Tasks.add (2, 2)
Simple usage:
>>> Add.s (2, 2)
Tasks.add (2, 2)
>>> Add.s (2, 2, debug=true)
Tasks.add (2, 2, debug=true)
More examples:
>>> s = Add.subtask ((2, 2), {' Debug ': True}, countdown=10)
>>> S.args
(2, 2)
>>> S.kwargs
{' Debug ': True}
>>> s.options
{' Countdown ': 10}
>>> Add.apply_async (args, Kwargs, **options)
>>> add.subtask (args, Kwargs, **options). Apply_async ()
>>> Add.apply_async ((2, 2), countdown=1)
>>> Add.subtask ((2, 2), countdown=1). Apply_async ()
This situation will be performed directly locally:
>>> Add (2, 2)
4
>>> Add.s (2, 2) ()
4
When you use S (), you cannot define option, only with Set
>>> Add.s (2, 2). Set (Countdown=1)
Proj.tasks.add (2, 2)
In many cases, parameters can be provided separately ( this is a very important feature!!!). ):
>>> partial = Add.s (2) # Incomplete signature
>>> Partial.delay (4) # 2 + 4
>>> Partial.apply_async (4,) # same
>>> s = Add.s (2, 2)
>>> S.delay (debug=true) #, add (2, 2, debug=true)
>>> s.apply_async (kwargs={' Debug ': True}) # same
In this case, option is overwritten with the original subtask definition:
>>> s = Add.subtask ((2, 2), countdown=10)
>>> S.apply_async (countdown=1) # countdown is now 1
You can derive the new subtask by cloning an existing one with an incomplete parameter subtask
>>> s = Add.s (2)
Proj.tasks.add (2)
>>> S.clone (args= (4,), kwargs={' Debug ': True})
Proj.tasks.add (2, 4, debug=true)
But this is the case:
>>> C = Add.s (32140,32492)
>>> C ()
64632
>>> C
Proj.agent.add (32140, 32492)
>>> k = C.clone (args= (24,434))
>>> K
Proj.agent.add (434, 32140, 32492) #调用会产生错误
>>>
Result is immutable by the immutable parameter setting
>>> Add.apply_async ((2, 2), Link=reset_buffers.subtask (immutable=true))
>>> Add.apply_async ((2, 2), link=reset_buffers.si ())
Here is an example;
>>> res = (add.si (2,5) | add.si (12,1) | add.si (2,2)) () #在这种情况下, chain only functions that combine tasks together, each SI () provides full parameters , otherwise error >>> Res.get () 4>>> res = (add.si (2,5) | add.si (12,1) | add.si (2,2)). Delay () >>> Res.get ( ) 4>>> Res.parent.get () #可以检查chain中各部分的result13 >>> RES.PARENT.P Arent.get (7)
Link is set to callback
The use of link is as follows:
Add.apply_async ((2, 2), LINK=OTHER_TASK.S ())
You can also use link to provide the parameters separately:
>>> Add.apply_async ((2, 2), Link=add.s (8))
Equivalent (+ +8)
#sora # Notes--Workflow