call func as interface

This demos a design pattern using call and callee task without local vars

The caller’s varss should always take priority than the the callee’s vars, if callee has already got same local vars defined, they will be overrided and used as default values

Applications

The possible application of this pattern is to call different implmentation task depending on certain condition, For example,

  1. you could conditionally deploy an application to AWS, Azure or K8s depending on criteria

  2. you could provistion backend storage solution using EBS, EFS

Demo

source

Main task yaml file
    vars:
      school: sydney grammar
    tasks:
    - name: task
      task:
      - func: call
        desc: call function with different vars
        vars:
          studentname: Tom
          school: sydney grammar
          gender: male
        do:
        - function
    - name: function
      desc: |
        as a design pattern, this is a function task
        it's better to not to use any local vars, in this
        way, the vars are passed in from caller call so
        that this function could be used by multiple ref tasks
      task:
      - func: shell
        desc: show school and student info
        do:
        - echo "studentname -> {{.studentname}} | gender -> {{.gender}}"
        - echo "school -> {{.school}}"
    
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 -> c0020
                 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/c0020
    module: [self], instance id: [dev], exec profile: []
    profile -  envVars:
    
    (*core.Cache)({
    })
    
    Task1: [task ==> task:  ]
    -Step1: [: call function with different vars ]
    self: final context exec vars:
    
    (*core.Cache)({
      "gender": "male",
      "school": "sydney grammar",
      "up_runtime_task_layer_number": 0,
      "studentname": "Tom"
    })
    
    =Task2: [task ==> function: as a design pattern, this is a function task
    it's better to not to use any local vars, in this
    way, the vars are passed in from caller call so
    that this function could be used by multiple ref tasks
     ]
    --Step1: [: show school and student info ]
    self: final context exec vars:
    
    (*core.Cache)({
      "school": "sydney grammar",
      "up_runtime_task_layer_number": 1,
      "studentname": "Tom",
      "gender": "male"
    })
    
    cmd( 1):
    echo "studentname -> {{.studentname}} | gender -> {{.gender}}"
    
    -
    studentname -> Tom | gender -> male
    
    -
     .. ok
    cmd( 2):
    echo "school -> {{.school}}"
    
    -
    school -> sydney grammar
    
    -
     .. ok
    . ok
    
Logs with different verbose level
Raw logs with different verbose level