Conditional On Task Status 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 28from hera.workflows import DAG, Workflow, script @script() def random(): import random p = random.random() if p <= 0.5: raise Exception("failure") @script() def success(): print("succeeded!") @script() def failure(): print("failed!") with Workflow(generate_name="dag-conditional-on-task-status-", entrypoint="d") as w: with DAG(name="d"): r = random() r.on_success(success()) r.on_failure(failure()) 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 51apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: dag-conditional-on-task-status- spec: entrypoint: d templates: - name: d dag: tasks: - name: random template: random - name: success depends: random.Succeeded template: success - name: failure depends: random.Failed template: failure - name: random script: image: python:3.10 source: |- import os import sys sys.path.append(os.getcwd()) import random p = random.random() if p <= 0.5: raise Exception('failure') command: - python - name: success script: image: python:3.10 source: |- import os import sys sys.path.append(os.getcwd()) print('succeeded!') command: - python - name: failure script: image: python:3.10 source: |- import os import sys sys.path.append(os.getcwd()) print('failed!') command: - python Comments