Add workflow execution process

This commit is contained in:
yoan
2024-11-18 19:40:24 +08:00
parent bde2147dd3
commit 775b12aec1
23 changed files with 741 additions and 21 deletions

View File

@@ -1,9 +1,22 @@
package domain
import "time"
import (
"fmt"
"strconv"
)
const (
WorkflowNodeTypeStart = "start"
WorkflowNodeTypeEnd = "end"
WorkflowNodeTypeApply = "apply"
WorkflowNodeTypeDeply = "deploy"
WorkflowNodeTypeNotify = "notify"
WorkflowNodeTypeBranch = "branch"
WorkflowNodeTypeCondition = "condition"
)
type Workflow struct {
Id string `json:"id"`
Meta
Name string `json:"name"`
Description string `json:"description"`
Type string `json:"type"`
@@ -11,8 +24,6 @@ type Workflow struct {
Draft *WorkflowNode `json:"draft"`
Enabled bool `json:"enabled"`
HasDraft bool `json:"hasDraft"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
}
type WorkflowNode struct {
@@ -29,11 +40,48 @@ type WorkflowNode struct {
Branches []WorkflowNode `json:"branches"`
}
func (n *WorkflowNode) GetConfigString(key string) string {
if v, ok := n.Config[key]; ok {
if s, ok := v.(string); ok {
return s
}
}
return ""
}
func (n *WorkflowNode) GetConfigBool(key string) bool {
if v, ok := n.Config[key]; ok {
if b, ok := v.(bool); ok {
return b
}
}
return false
}
func (n *WorkflowNode) GetConfigInt64(key string) int64 {
// 先转成字符串,再转成 int64
if v, ok := n.Config[key]; ok {
temp := fmt.Sprintf("%v", v)
if i, err := strconv.ParseInt(temp, 10, 64); err == nil {
return i
}
}
return 0
}
type WorkflowNodeIo struct {
Label string `json:"label"`
Name string `json:"name"`
Type string `json:"type"`
Required bool `json:"required"`
Label string `json:"label"`
Name string `json:"name"`
Type string `json:"type"`
Required bool `json:"required"`
Value any `json:"value"`
ValueSelector WorkflowNodeIoValueSelector `json:"valueSelector"`
}
type WorkflowNodeIoValueSelector struct {
Id string `json:"id"`
Name string `json:"name"`
}
type WorkflowRunReq struct {