How to retrieve results/output from workflow tasks after the workflow is complete #1464
-
If I create and submit a workflow, how can I pull results out from the tasks? In a related note, is there a way to define at the workflow level what the "Outputs" are, instead of the client having to know which specific tasks to pull which specific output from for later use? e.g. # my_workflow.py
from hera.workflows import Workflow, script
@script()
def hello(s: str) -> str:
return("Hello, {s}!".format(s=s))
with Workflow(
generate_name="hello-world-",
entrypoint="hello",
arguments={"s": "world"},
) as w:
hello() # submit_script.py
from my_workflow import w
w.arguments = {"s": "Hera"}
w.create(wait=True)
if not (w.status and w.status.phase == "Succeeded"):
raise RuntimeError('workflow failed')
# what next?
output_from_w =filter(
lambda n: n.display_name == "hello",
m.status.nodes.values(), # why is the list of nodes in the status attribute? copied from https://hera.readthedocs.io/en/stable/examples/workflows/use-cases/testing_templates_and_workflows/
)[0].???? # how do I access the output from the task What I'm trying to achieve is having a single python function that takes in some arguments, submits them into a workflow for execution on different containers, waits for the workflow to finish, then returns the final result. Do all outputs have to be artifacts? is the way to access those outputs different if they are not artifacts? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
To answer
first - I don't think there is. A Workflow is just an abstraction to hold
For parameters, you can take inspiration from this test: hera/tests/submissions/test_optional_input_parameter.py Lines 50 to 51 in 0d283df The For Artifacts, you can then use a hera/src/hera/workflows/service.py Line 1355 in 0d283df |
Beta Was this translation helpful? Give feedback.
-
Follow up question - the response from e.g this is a response I got from the apo. It has real data, but nothing sensitive, just some custom python dataclass objects with junk data used for testing. What do I do with it to turn it back into a python object? I used
If I use |
Beta Was this translation helpful? Give feedback.
-
I was able to figure it out. It's the bytes of a |
Beta Was this translation helpful? Give feedback.
To answer
first - I don't think there is. A Workflow is just an abstraction to hold
templates
, which themselves have inputs and outputs.For parameters, you can take inspiration from this test:
hera/tests/submissions/test_optional_input_parameter.py
Lines 50 to 51 in 0d283df
The
node.outputs
follows the spec forOutputs
https://argo-workflows.readt…