The key to use this patter is to use multiple layers of call hierarchical structure, for example, main task, the routing layer func, the implmentation layer tasks. You will put all local vars to a call func, so that the global vars scope will not be polluted, changes will be made and applied within the layer of called implementation only
tasks:
- name: task
task:
- func: call
vars:
layer1_aaa: layer1_aaa
layer1_bbb: layer1_bbb
do:
- layer2
loop:
- layer1-tom
- layer1-peter
- layer1-james
- name: layer2
task:
- func: cmd
do:
- name: print
cmd: 'hello {{.loopitem}}'
- name: print
cmd: 'hello layer1_aaa: {{.layer1_aaa}}'
- func: cmd
do:
- name: print
cmd: 'hello {{.loopitem}}'
- name: print
cmd: 'hello layer1_bbb: {{.layer1_bbb}}'
loading [Config]: ./tests/functests/upconfig.yml
Main config:
Version -> 1.0.0
RefDir -> ./tests/functests
WorkDir -> cwd
AbsWorkDir -> /up_project/up
TaskFile -> c0094
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/c0094
module: [self], instance id: [dev], exec profile: []
profile - envVars:
(*core.Cache)({
})
Task1: [task ==> task: ]
-Step1:
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0,
"layer1_bbb": "layer1_bbb",
"layer1_aaa": "layer1_aaa"
})
=Task2: [task ==> layer2: ]
--Step1:
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 1,
"layer1_bbb": "layer1_bbb",
"layer1_aaa": "layer1_aaa",
"loopitem": "layer1-tom",
"loopindex": 0,
"loopindex1": 1
})
~~SubStep1: [print: ]
hello layer1-tom
~~SubStep2: [print: ]
hello layer1_aaa: layer1_aaa
--Step2:
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 1,
"layer1_bbb": "layer1_bbb",
"layer1_aaa": "layer1_aaa",
"loopitem": "layer1-tom",
"loopindex": 0,
"loopindex1": 1
})
~~SubStep1: [print: ]
hello layer1-tom
~~SubStep2: [print: ]
hello layer1_bbb: layer1_bbb
=Task2: [task ==> layer2: ]
--Step1:
self: final context exec vars:
(*core.Cache)({
"layer1_bbb": "layer1_bbb",
"layer1_aaa": "layer1_aaa",
"loopitem": "layer1-peter",
"loopindex": 1,
"loopindex1": 2,
"up_runtime_task_layer_number": 1
})
~~SubStep1: [print: ]
hello layer1-peter
~~SubStep2: [print: ]
hello layer1_aaa: layer1_aaa
--Step2:
self: final context exec vars:
(*core.Cache)({
"loopindex1": 2,
"up_runtime_task_layer_number": 1,
"layer1_bbb": "layer1_bbb",
"layer1_aaa": "layer1_aaa",
"loopitem": "layer1-peter",
"loopindex": 1
})
~~SubStep1: [print: ]
hello layer1-peter
~~SubStep2: [print: ]
hello layer1_bbb: layer1_bbb
=Task2: [task ==> layer2: ]
--Step1:
self: final context exec vars:
(*core.Cache)({
"loopindex1": 3,
"up_runtime_task_layer_number": 1,
"layer1_bbb": "layer1_bbb",
"layer1_aaa": "layer1_aaa",
"loopitem": "layer1-james",
"loopindex": 2
})
~~SubStep1: [print: ]
hello layer1-james
~~SubStep2: [print: ]
hello layer1_aaa: layer1_aaa
--Step2:
self: final context exec vars:
(*core.Cache)({
"layer1_bbb": "layer1_bbb",
"layer1_aaa": "layer1_aaa",
"loopitem": "layer1-james",
"loopindex": 2,
"loopindex1": 3,
"up_runtime_task_layer_number": 1
})
~~SubStep1: [print: ]
hello layer1-james
~~SubStep2: [print: ]
hello layer1_bbb: layer1_bbb