finally/resuce support in task level
Showcases that all tasks with finally block will be guranteed to do the final code block
Demo
source
Main task yaml file
vars:
global_aa: aa
tasks:
- name: task
task:
- func: block
desc: loop through test cases
vars:
local_bb: bb
dvars:
- name: task_tt
value: tt
flags: [taskScope]
loop:
- item1
- item2
do:
- func: shell
do:
- 'echo "main task start"'
- func: call
do: cc
finally:
- func: shell
vars:
finally_task: ff
do:
- 'echo "main task final"'
- name: cc
task:
- func: shell
do:
- echo "in cc ...."
finally:
- func: shell
vars:
finally_cc: cc
name: close_file
desc: |
ensure the opened file is closed
do:
- 'echo "close the file {{.loopitem}}"'
Main log file
loading [Config]: ./tests/functests/upconfig.yml
Main config:
Version -> 1.0.0
RefDir -> ./tests/functests
WorkDir -> cwd
AbsWorkDir -> /up_project/up
TaskFile -> c0192
Verbose -> vvv
ModuleName -> self
ShellType -> /bin/sh
MaxCallLayers -> 8
Timeout -> 3600000
MaxModuelCallLayers -> 256
EntryTask -> task
ModRepoUsernameRef ->
ModRepoPasswordRef ->
work dir: /up_project/up
-exec task: task
loading [Task]: ./tests/functests/c0192
module: [self], instance id: [dev], exec profile: []
profile - envVars:
(*core.Cache)({
})
Task1: [task ==> task: ]
-Step1: [: loop through test cases ]
self: final context exec vars:
(*core.Cache)({
"task_tt": "tt",
"global_aa": "aa",
"up_runtime_task_layer_number": 0,
"local_bb": "bb"
})
-Step1:
self: final context exec vars:
(*core.Cache)({
"task_tt": "tt",
"local_bb": "bb",
"loopitem": "item1",
"loopindex": 0,
"loopindex1": 1,
"global_aa": "aa",
"up_runtime_task_layer_number": 0
})
cmd( 1):
echo "main task start"
-
main task start
-
.. ok
. ok
-Step2:
self: final context exec vars:
(*core.Cache)({
"loopitem": "item1",
"loopindex": 0,
"global_aa": "aa",
"last_result": (*utils.ExecResult)({
Cmd: "echo \"main task start\"",
Code: 0,
Output: "main task start",
ErrMsg: ""
}),
"up_runtime_task_layer_number": 0,
"task_tt": "tt",
"loopindex1": 1,
"local_bb": "bb"
})
=Task2: [task ==> cc: ]
--Step1:
self: final context exec vars:
(*core.Cache)({
"loopindex": 0,
"global_aa": "aa",
"last_result": (*utils.ExecResult)({
Cmd: "echo \"main task start\"",
Code: 0,
Output: "main task start",
ErrMsg: ""
}),
"up_runtime_task_layer_number": 1,
"task_tt": "tt",
"loopindex1": 1,
"local_bb": "bb",
"loopitem": "item1"
})
cmd( 1):
echo "in cc ...."
-
in cc ....
-
.. ok
. ok
task Finally:
-Step1: [
close_fileensure the opened file is closed
]
self: final context exec vars:
(*core.Cache)({
"loopitem": "item1",
"loopindex": 0,
"global_aa": "aa",
"up_runtime_task_layer_number": 1,
"finally_cc": "cc",
"task_tt": "tt",
"loopindex1": 1,
"local_bb": "bb"
})
cmd( 1):
echo "close the file {{.loopitem}}"
-
close the file item1
-
.. ok
. ok
-Step1:
self: final context exec vars:
(*core.Cache)({
"global_aa": "aa",
"up_runtime_task_layer_number": 0,
"task_tt": "tt",
"local_bb": "bb",
"loopitem": "item2",
"loopindex": 1,
"loopindex1": 2
})
cmd( 1):
echo "main task start"
-
main task start
-
.. ok
. ok
-Step2:
self: final context exec vars:
(*core.Cache)({
"loopindex1": 2,
"local_bb": "bb",
"loopitem": "item2",
"loopindex": 1,
"global_aa": "aa",
"last_result": (*utils.ExecResult)({
Cmd: "echo \"main task start\"",
Code: 0,
Output: "main task start",
ErrMsg: ""
}),
"up_runtime_task_layer_number": 0,
"task_tt": "tt"
})
=Task2: [task ==> cc: ]
--Step1:
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 1,
"task_tt": "tt",
"loopindex1": 2,
"local_bb": "bb",
"loopitem": "item2",
"loopindex": 1,
"global_aa": "aa",
"last_result": (*utils.ExecResult)({
Cmd: "echo \"main task start\"",
Code: 0,
Output: "main task start",
ErrMsg: ""
})
})
cmd( 1):
echo "in cc ...."
-
in cc ....
-
.. ok
. ok
task Finally:
-Step1: [
close_fileensure the opened file is closed
]
self: final context exec vars:
(*core.Cache)({
"global_aa": "aa",
"up_runtime_task_layer_number": 1,
"task_tt": "tt",
"loopindex1": 2,
"local_bb": "bb",
"finally_cc": "cc",
"loopitem": "item2",
"loopindex": 1
})
cmd( 1):
echo "close the file {{.loopitem}}"
-
close the file item2
-
.. ok
. ok
task Finally:
Step1:
self: final context exec vars:
(*core.Cache)({
"global_aa": "aa",
"up_runtime_task_layer_number": 1,
"task_tt": "tt",
"finally_task": "ff"
})
cmd( 1):
echo "main task final"
-
main task final
-
.. ok
. ok
Logs with different verbose level
Raw logs with different verbose level
Other references: