github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0187.yml (about) 1 doc_meta: | 2 folder: flow-controll 3 title: complex task finally in sub task 4 head: | 5 Showcases comlex sub task with finally block 6 7 sections: 8 - title: Demo 9 log: yes 10 11 - title: What's the difference betwee the step level and task level finally cleanup and rescue? 12 content: | 13 The only difference would be that in the step level, you would be able to obtain the exec result and then conditionally do something about it 14 15 related: 16 refs: 17 - title: shell func 18 link: ../../quick-start/c0002/ 19 - title: error handling 20 link: ../../test-debug/error_handling/ 21 - title: finally and rescue 22 link: ../../flow-controll/c0174/ 23 24 25 TODO: 26 notes: 27 - add finally support to tasks level 28 29 tasks: 30 31 - 32 name: task 33 task: 34 35 - 36 func: block 37 loop: 38 - item1 39 - item2 40 desc: task 41 do: 42 - func: call 43 do: sub_task_layer1 44 45 - 46 name: sub_task_layer1 47 desc: sub_task_layer1 48 task: 49 50 - 51 func: cmd 52 do: 53 - name: print 54 cmd: "in sub_task_layer1" 55 56 - 57 func: block 58 loop: 59 - aaaa 60 - bbbb 61 desc: task 62 do: 63 64 - 65 func: cmd 66 desc: processing ..... 67 do: 68 - name: print 69 cmd: '{{.loopitem}}' 70 71 - 72 func: call 73 loop: 74 - xxx 75 - yyy 76 do: 77 - sub_task_layer2 78 79 - 80 name: sub_task_layer2 81 task: 82 83 - 84 func: shell 85 name: step1 86 desc: step 1 87 flags: [ignoreError] 88 do: 89 - 'echo """opening file: {{.loopitem}}"""' 90 - echo "hello"|grep "world" 91 92 - 93 func: cmd 94 name: step2 95 desc: | 96 in this case, since there is no ignoreError, the exception was captured by task level finaly code block 97 opened file is safely closed 98 to make the flow to continue to reach step2, use ignoreError 99 do: 100 - name: print 101 cmd: step 2 102 103 desc: | 104 without rescue, the execution will return a non-zero return code in shell and also report the error 105 with rescue, the program will return 0 106 rescue: true 107 finally: 108 - 109 func: shell 110 name: close_file 111 desc: | 112 ensure the opened file is closed 113 do: 114 - echo "close the file ....."