github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/f0188.yml (about)

     1  doc_meta: |
     2    folder: flow-controll
     3    title: finally/resuce support in subtask level
     4    head: |
     5      Showcases that you could make the workflow to pass through with cleanup, however you can still make the exit code  as none zero to mark it fail
     6  
     7    sections:
     8      - title: Demo
     9        log: yes
    10  
    11    related:
    12      refs:
    13        - title: shell func
    14          link: ../../quick-start/c0002/
    15        - title: error handling
    16          link: ../../test-debug/error_handling/
    17        - title: finally and rescue
    18          link: ../../flow-controll/c0174/
    19        - title: finally block
    20          link: ../../flow-controll/c0183/
    21        - title: finally block
    22          link: ../../flow-controll/c0184/
    23        - title: finally block
    24          link: ../../flow-controll/c0187/
    25  
    26  notes:
    27    - add finally support to tasks level
    28  
    29  tasks:
    30  
    31    -
    32      name: task
    33      task:
    34  
    35        -
    36          func: call
    37          desc: |
    38            expect sub_task to close file each time in loop iteration
    39          loop:
    40            - item1
    41            - item2
    42            - item3
    43          do:
    44            - sub_task
    45  
    46    -
    47      name: sub_task
    48      task:
    49  
    50        -
    51          func: cmd
    52          do:
    53            - name: print
    54              cmd: 'case {{.loopitem}}'
    55  
    56        -
    57          func: shell
    58          name: step1
    59          desc: conditionall trigger the error
    60          do:
    61            - echo "case {{.loopitem}} "
    62            - echo "hello"|grep "world"
    63          if: '{{eq .loopitem "item2"}}'
    64  
    65        -
    66          func: cmd
    67          name: step2
    68          desc: |
    69            in this case, since there is no ignoreError, the exception was captured by task level finaly code block
    70            opened file is safely closed
    71            to make the flow to continue to reach step2, use ignoreError
    72          do:
    73            - name: print
    74              cmd: step 2
    75  
    76      desc: |
    77        without rescue, the execution will return a non-zero  return code in shell and also report the error
    78        with rescue, the program will return 0
    79      rescue: true
    80      finally:
    81        -
    82          func: shell
    83          name: close_file
    84          desc: |
    85            ensure the opened file is closed
    86          do:
    87            - echo "close the file ....."