Conditional This example showcases conditional execution on success, failure, and error HeraYAML 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31from hera.workflows import DAG, Workflow, script @script() def random(): import random p = random.random() if p <= 0.5: raise Exception("failure") print("success") @script() def success(): print("success") @script() def failure(): print("failure") with Workflow(generate_name="conditional-", entrypoint="d") as w: with DAG(name="d"): r = random() s = success() f = failure() r.on_success(s) r.on_failure(f) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: conditional- spec: entrypoint: d templates: - dag: tasks: - name: random template: random - depends: random.Succeeded name: success template: success - depends: random.Failed name: failure template: failure name: d - name: random script: command: - python image: python:3.8 source: |- import os import sys sys.path.append(os.getcwd()) import random p = random.random() if p <= 0.5: raise Exception('failure') print('success') - name: success script: command: - python image: python:3.8 source: |- import os import sys sys.path.append(os.getcwd()) print('success') - name: failure script: command: - python image: python:3.8 source: |- import os import sys sys.path.append(os.getcwd()) print('failure') Comments