-
Notifications
You must be signed in to change notification settings - Fork 81
/
task.go
89 lines (77 loc) · 3.44 KB
/
task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2022 The kubegems.io Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package workflow
import (
"encoding/json"
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// task 存储路径为 /{prefix}/{task-name}/{uid}
// Task 任务,一个task为一个整体性的任务,其下可以包含子任务,分支任务,嵌套任务, 触发其他任务等。
// 任务支持重试
// 支持失败策略
// task 之间可以进行值传递
// task 可以设置为同步执行
// task 可以设置为定时执行
type Task struct {
UID string `json:"uid,omitempty"`
Name string `json:"name,omitempty"` // 任务名称,例如 更新镜像,同步数据等。
Group string `json:"group,omitempty"` // 任务类型分组
Steps []Step `json:"steps,omitempty"`
CreationTimestamp metav1.Time `json:"creationTimestamp,omitempty"`
Addtionals map[string]string `json:"addtionals,omitempty"` // 额外信息
Status *TaskStatus `json:"status,omitempty"`
}
type Step struct {
Name string `json:"name,omitempty"`
Function string `json:"function,omitempty"` // 任务所使用的 函数/组件/插件
Args []interface{} `json:"args,omitempty"` // 对应的参数
SubSteps []Step `json:"subSteps,omitempty"` // 子任务
Status *TaskStatus `json:"status,omitempty"`
}
type jsonArgsTask struct {
UID string `json:"uid,omitempty"`
Name string `json:"name,omitempty"`
Group string `json:"group,omitempty"`
Steps []*jsonArgsStep `json:"steps,omitempty"`
CreationTimestamp metav1.Time `json:"creationTimestamp,omitempty"`
Addtionals map[string]string `json:"addtionals,omitempty"` // 额外信息
Status TaskStatus `json:"status,omitempty"`
}
type jsonArgsStep struct {
Name string `json:"name,omitempty"`
Function string `json:"function,omitempty"`
Args []json.RawMessage `json:"args,omitempty"`
SubSteps []*jsonArgsStep `json:"subSteps,omitempty"`
Status TaskStatus `json:"status,omitempty"`
Timeout time.Duration `json:"timeout,omitempty"` // 任务执行超时
}
func ArgsOf(args ...interface{}) []interface{} {
return args
}
type TaskStatusCode string
const (
TaskStatusPending TaskStatusCode = "Pending"
TaskStatusRunning TaskStatusCode = "Running"
TaskStatusSuccess TaskStatusCode = "Success"
TaskStatusError TaskStatusCode = "Error"
)
type TaskStatus struct {
StartTimestamp metav1.Time `json:"startTimestamp,omitempty"`
FinishTimestamp metav1.Time `json:"finishTimestamp,omitempty"`
Status TaskStatusCode `json:"status,omitempty"`
Result []interface{} `json:"result,omitempty"`
Executer string `json:"executer,omitempty"`
Message string `json:"message,omitempty"`
}