-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Flaviu Vadan <[email protected]>
- Loading branch information
1 parent
8cf44d1
commit 0a9385c
Showing
30 changed files
with
744 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Coinflip | ||
|
||
|
||
|
||
|
||
|
||
## Hera | ||
|
||
```python | ||
from hera.workflows import DAG, Workflow, script | ||
|
||
|
||
@script() | ||
def flip(): | ||
import random | ||
|
||
result = "heads" if random.randint(0, 1) == 0 else "tails" | ||
print(result) | ||
|
||
|
||
@script() | ||
def heads(): | ||
print("it was heads") | ||
|
||
|
||
@script() | ||
def tails(): | ||
print("it was tails") | ||
|
||
|
||
with Workflow(generate_name="coinflip-", entrypoint="d") as w: | ||
with DAG(name="d") as s: | ||
f = flip() | ||
heads().on_other_result(f, "heads") | ||
tails().on_other_result(f, "tails") | ||
``` | ||
|
||
## YAML | ||
|
||
```yaml | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: coinflip- | ||
spec: | ||
entrypoint: d | ||
templates: | ||
- dag: | ||
tasks: | ||
- name: flip | ||
template: flip | ||
- depends: flip | ||
name: heads | ||
template: heads | ||
when: '{{tasks.flip.outputs.result}} == heads' | ||
- depends: flip | ||
name: tails | ||
template: tails | ||
when: '{{tasks.flip.outputs.result}} == tails' | ||
name: d | ||
- name: flip | ||
script: | ||
command: | ||
- python | ||
image: python:3.7 | ||
source: 'import os | ||
import sys | ||
sys.path.append(os.getcwd()) | ||
import random | ||
result = "heads" if random.randint(0, 1) == 0 else "tails" | ||
print(result) | ||
' | ||
- name: heads | ||
script: | ||
command: | ||
- python | ||
image: python:3.7 | ||
source: 'import os | ||
import sys | ||
sys.path.append(os.getcwd()) | ||
print("it was heads") | ||
' | ||
- name: tails | ||
script: | ||
command: | ||
- python | ||
image: python:3.7 | ||
source: 'import os | ||
import sys | ||
sys.path.append(os.getcwd()) | ||
print("it was tails") | ||
' | ||
``` |
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,101 @@ | ||
# Dag Conditional Parameters | ||
|
||
|
||
|
||
|
||
|
||
## Hera | ||
|
||
```python | ||
from hera.expr import g | ||
from hera.workflows import DAG, Parameter, Workflow, script | ||
|
||
|
||
@script(add_cwd_to_sys_path=False, image="python:alpine3.6") | ||
def heads(): | ||
print("heads") | ||
|
||
|
||
@script(add_cwd_to_sys_path=False, image="python:alpine3.6") | ||
def tails(): | ||
print("tails") | ||
|
||
|
||
@script(add_cwd_to_sys_path=False, image="python:alpine3.6") | ||
def flip_coin(): | ||
import random | ||
|
||
print("heads" if random.randint(0, 1) == 0 else "tails") | ||
|
||
|
||
with Workflow( | ||
generate_name="dag-conditional-parameter-", | ||
entrypoint="main", | ||
) as w: | ||
with DAG(name="main") as main_dag: | ||
fc = flip_coin(name="flip-coin") | ||
h = heads(name="heads").on_other_result(fc, "heads") | ||
t = tails(name="tails").on_other_result(fc, "tails") | ||
|
||
expression = g.tasks["flip-coin"].outputs.result == "heads" | ||
expression = expression.check(g.tasks.heads.outputs.result, g.tasks.tails.outputs.result) # type: ignore | ||
main_dag.outputs = [Parameter(name="stepresult", value_from={"expression": str(expression)})] | ||
``` | ||
|
||
## YAML | ||
|
||
```yaml | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: dag-conditional-parameter- | ||
spec: | ||
entrypoint: main | ||
templates: | ||
- dag: | ||
tasks: | ||
- name: flip-coin | ||
template: flip-coin | ||
- depends: flip-coin | ||
name: heads | ||
template: heads | ||
when: '{{tasks.flip-coin.outputs.result}} == heads' | ||
- depends: flip-coin | ||
name: tails | ||
template: tails | ||
when: '{{tasks.flip-coin.outputs.result}} == tails' | ||
name: main | ||
outputs: | ||
parameters: | ||
- name: stepresult | ||
valueFrom: | ||
expression: 'tasks[''flip-coin''].outputs.result == ''heads'' ? tasks.heads.outputs.result | ||
: tasks.tails.outputs.result' | ||
- name: flip-coin | ||
script: | ||
command: | ||
- python | ||
image: python:alpine3.6 | ||
source: 'import random | ||
print("heads" if random.randint(0, 1) == 0 else "tails") | ||
' | ||
- name: heads | ||
script: | ||
command: | ||
- python | ||
image: python:alpine3.6 | ||
source: 'print("heads") | ||
' | ||
- name: tails | ||
script: | ||
command: | ||
- python | ||
image: python:alpine3.6 | ||
source: 'print("tails") | ||
' | ||
``` |
89 changes: 89 additions & 0 deletions
89
docs/examples/workflows/dag_diamond_with_callable_decorators.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,89 @@ | ||
# Dag Diamond With Callable Decorators | ||
|
||
|
||
|
||
|
||
|
||
## Hera | ||
|
||
```python | ||
from hera.workflows import ( | ||
DAG, | ||
Workflow, | ||
script, | ||
) | ||
|
||
|
||
@script(add_cwd_to_sys_path=False, image="python:alpine3.6") | ||
def echo(message): | ||
print(message) | ||
|
||
|
||
with Workflow(generate_name="dag-diamond-", entrypoint="diamond") as w: | ||
with DAG(name="diamond"): | ||
A = echo(name="A", arguments={"message": "A"}) | ||
B = echo(name="B", arguments={"message": "B"}) | ||
C = echo(name="C", arguments={"message": "C"}) | ||
D = echo(name="D", arguments={"message": "D"}) | ||
A >> [B, C] >> D | ||
``` | ||
|
||
## YAML | ||
|
||
```yaml | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: dag-diamond- | ||
spec: | ||
entrypoint: diamond | ||
templates: | ||
- dag: | ||
tasks: | ||
- arguments: | ||
parameters: | ||
- name: message | ||
value: A | ||
name: A | ||
template: echo | ||
- arguments: | ||
parameters: | ||
- name: message | ||
value: B | ||
depends: A | ||
name: B | ||
template: echo | ||
- arguments: | ||
parameters: | ||
- name: message | ||
value: C | ||
depends: A | ||
name: C | ||
template: echo | ||
- arguments: | ||
parameters: | ||
- name: message | ||
value: D | ||
depends: B && C | ||
name: D | ||
template: echo | ||
name: diamond | ||
- inputs: | ||
parameters: | ||
- name: message | ||
name: echo | ||
script: | ||
command: | ||
- python | ||
image: python:alpine3.6 | ||
source: 'import json | ||
try: message = json.loads(r''''''{{inputs.parameters.message}}'''''') | ||
except: message = r''''''{{inputs.parameters.message}}'''''' | ||
print(message) | ||
' | ||
``` |
2 changes: 1 addition & 1 deletion
2
docs/examples/workflows/http.md → docs/examples/workflows/http_.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Http | ||
# Http | ||
|
||
|
||
|
||
|
Oops, something went wrong.