You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NOTE: This is not strictly a bug or feature request. It's quite possible Celery wasn't meant to handle this type of problem.
Is it possible to represent all DAGs using Celery canvases? My hunch is no, but I wanted to double check.
The graph I'd like to represent is something like:
a = A()
b = B(a)
c = C(a, b)
Where A, B, and C are tasks. So, C receives both the output of A and the output of B whilst B receives the output of A. Is something like this possible?
Reacted by Riyad Parvez, Peter Hadlaw, Julian Steiner, Matthieu Bizien and Sam Koelle
That's one way to do it, but you could also design a primitive that forwards results:
@app.task(bind=True)defforward(self, result, sig):
# convert JSON serialized signature back to Signaturesig=self.app.signature(sig)
# get the return value of the provided task signatureresult2=sig()
# next task will receive tuple of (result_A, result_B)return (result, result2)
@app.taskdefC(self, (Ares, Bres)):
returnAres+Bresworkflow= (A.s() |forward.s(B.s()) |C.s())
NOTE: Using unpacking in the function signature is not allowed in Python 3, there you'd have to do:
Great, thanks for the quick response. I like forward quite a bit. The downsides I see are that it copies the previous result and uses some worker time, but those probably don't matter in most situations.
It looks like something changed in the latest release. @ask if I run the way you have mentioned (first way) I get an error "RuntimeError: Never call result.get() within a task! It refers to the document page which I have gone through. Any help will be appreciated here.
Activity
ask commentedon Dec 8, 2016
A workflow is definitely a tree structure, but I guess it's not a graph as long as it's impossible to refer to an existing task.
There was a feature request wanting something like this to be possible:
but I'm not sure how that can logically work, considering that the return value of C cannot be passed
on to A, when A already finished executing.
If you merely want to refer to the result of a previously executed task, then that is definitely possible:
At this point
Cwould receive two arguments: the result ofBand the result object (promise) of the A task:That's one way to do it, but you could also design a primitive that forwards results:
NOTE: Using unpacking in the function signature is not allowed in Python 3, there you'd have to do:
matthewatabet commentedon Dec 9, 2016
Great, thanks for the quick response. I like
forwardquite a bit. The downsides I see are that it copies the previous result and uses some worker time, but those probably don't matter in most situations.Thanks for the help!
Yashg19 commentedon Jun 12, 2017
It looks like something changed in the latest release. @ask if I run the way you have mentioned (first way) I get an error "RuntimeError: Never call result.get() within a task! It refers to the document page which I have gone through. Any help will be appreciated here.