-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hera tour to walkthrough (#1002)
* hera-tour part of walkthrough based on upcoming ArgoCon EU 2024 talk, link will be up after * Add `use_cases/testing_templates_and_workflows.py` to show how to test script templates and workflows * Tidy up other examples which will used in the talk --------- Signed-off-by: Elliot Gunton <egunton@bloomberg.net>
- Loading branch information
1 parent
5c252ac
commit 61bf73c
Showing
14 changed files
with
622 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
docs/examples/workflows/use-cases/testing_templates_and_workflows.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# Testing Templates And Workflows | ||
|
||
|
||
|
||
|
||
|
||
|
||
=== "Hera" | ||
|
||
```python linenums="1" | ||
from hera.shared import global_config | ||
from hera.workflows import DAG, RunnerScriptConstructor, Script, Workflow, WorkflowsService, script | ||
|
||
try: | ||
from pydantic.v1 import BaseModel | ||
except ImportError: | ||
from pydantic import BaseModel | ||
|
||
global_config.set_class_defaults(Script, constructor=RunnerScriptConstructor()) | ||
|
||
|
||
class Rectangle(BaseModel): | ||
length: float | ||
width: float | ||
|
||
def area(self) -> float: | ||
return self.length * self.width | ||
|
||
|
||
@script(constructor="runner", image="my-built-python-image") | ||
def calculate_area_of_rectangle(rectangle: Rectangle) -> float: | ||
return rectangle.area() | ||
|
||
|
||
with Workflow( | ||
generate_name="dag-", | ||
entrypoint="dag", | ||
namespace="argo", | ||
workflows_service=WorkflowsService(host="https://localhost:2746"), | ||
) as w: | ||
with DAG(name="dag"): | ||
A = calculate_area_of_rectangle( | ||
name="rectangle-1", arguments={"rectangle": Rectangle(length=1.2, width=3.4).json()} | ||
) | ||
B = calculate_area_of_rectangle( | ||
name="rectangle-2", arguments={"rectangle": Rectangle(length=4.3, width=2.1).json()} | ||
) | ||
A >> B | ||
|
||
|
||
def test_calculate_area_of_rectangle(): | ||
r = Rectangle(length=2.0, width=3.0) | ||
assert calculate_area_of_rectangle(r) == 6.0 | ||
|
||
|
||
def test_create_workflow(): | ||
model_workflow = w.create(wait=True) | ||
assert model_workflow.status and model_workflow.status.phase == "Succeeded" | ||
|
||
echo_node = next( | ||
filter( | ||
lambda n: n.display_name == "echo", | ||
model_workflow.status.nodes.values(), | ||
) | ||
) | ||
assert echo_node.outputs.parameters[0].value == "my value" | ||
``` | ||
|
||
=== "YAML" | ||
|
||
```yaml linenums="1" | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: dag- | ||
namespace: argo | ||
spec: | ||
entrypoint: dag | ||
templates: | ||
- dag: | ||
tasks: | ||
- arguments: | ||
parameters: | ||
- name: rectangle | ||
value: '{"length": 1.2, "width": 3.4}' | ||
name: rectangle-1 | ||
template: calculate-area-of-rectangle | ||
- arguments: | ||
parameters: | ||
- name: rectangle | ||
value: '{"length": 4.3, "width": 2.1}' | ||
depends: rectangle-1 | ||
name: rectangle-2 | ||
template: calculate-area-of-rectangle | ||
name: dag | ||
- inputs: | ||
parameters: | ||
- name: rectangle | ||
name: calculate-area-of-rectangle | ||
script: | ||
args: | ||
- -m | ||
- hera.workflows.runner | ||
- -e | ||
- examples.workflows.use_cases.testing_templates_and_workflows:calculate_area_of_rectangle | ||
command: | ||
- python | ||
image: my-built-python-image | ||
source: '{{inputs.parameters}}' | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.