github.com/oam-dev/kubevela@v1.9.11/pkg/builtin/task.go (about) 1 /* 2 Copyright 2021 The KubeVela Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package builtin 18 19 import ( 20 "errors" 21 22 "cuelang.org/go/cue" 23 24 // RegisterRunner all build jobs here, so the jobs will automatically registered before RunBuildInTasks run. 25 _ "github.com/oam-dev/kubevela/pkg/builtin/build" 26 _ "github.com/oam-dev/kubevela/pkg/builtin/http" 27 28 "github.com/oam-dev/kubevela/pkg/builtin/registry" 29 cmdutil "github.com/oam-dev/kubevela/pkg/utils/util" 30 ) 31 32 // RunBuildInTasks do initializing tasks for appfile. 33 // You should call RunBuildInTasks instead of directly call registry.Run as the package will automatically import internal packages for built-in task 34 func RunBuildInTasks(spec map[string]interface{}, io cmdutil.IOStreams) (map[string]interface{}, error) { 35 return registry.Run(spec, io) 36 } 37 38 // RunTaskByKey do task by key 39 func RunTaskByKey(key string, v cue.Value, meta *registry.Meta) (interface{}, error) { 40 task := registry.LookupRunner(key) 41 if task == nil { 42 return nil, errors.New("there is no http task in task registry") 43 } 44 runner, err := task(v) 45 if err != nil { 46 return nil, err 47 } 48 return runner.Run(meta) 49 }