How should I be updating my Tasks for hera v5? #615
-
Right now I'm using something like this: # create a simple function so we can use a named Parameter
def run_command(cmd: str) -> str:
return cmd
task = Task(
name="cmd-template",
source=run_command,
command=["bash"],
image=docker_image,
inputs=[Parameter(name="cmd", default="echo Hello Argo")],
) on hera v5, I get the following error:
What is the recommended way to update my code to work with the new hera? (Related to #562) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey @dmerrick! Thanks for the question! If you want to maintain a structure that closely matches the example you can write something like: from hera.workflows import Script, Workflow
def run_command(cmd: str) -> str:
return cmd
task = Script(
name="cmd-template",
source=run_command,
command=["bash"],
image=docker_image,
inputs=[Parameter(name="cmd", default="echo Hello Argo")],
) If you want to take advantage of some of the new v5 features (single script example and Hera runner example): from hera.workflows import script, Workflow
@script(image="docker_image", constructor="runner") # you can also use GlobalHooks to set this! See example above
def run_command(cmd: str = "echo Hello Argo") -> str: # the kwarg will auto-create the Parameter with name + default
return cmd # if we want to `return` here, need the Hera runner
with Workflow(generate_name="dmerrick-", entrypoint="run_command") as w:
run_command() WhyIn v4 the idea of a "task" and a "template" were one and the same. The intent was to save users from having to define a template and then use that template in a task. However, that caused confusion.. so they are unwrapped in V5, as they are in Argo Workflows officially. The |
Beta Was this translation helpful? Give feedback.
-
@flaviuvadan thanks for this detailed answer We're not using the contextmanager pattern right now, we've been using |
Beta Was this translation helpful? Give feedback.
Hey @dmerrick! Thanks for the question! If you want to maintain a structure that closely matches the example you can write something like:
If you want to take advantage of some of the new v5 features (single script example and Hera runner example):