mirror of
https://github.com/usual2970/certimate.git
synced 2025-07-20 18:07:59 +00:00
add execute result branch
This commit is contained in:
27
internal/workflow/node-processor/execute_failure_node.go
Normal file
27
internal/workflow/node-processor/execute_failure_node.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package nodeprocessor
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/usual2970/certimate/internal/domain"
|
||||
)
|
||||
|
||||
type executeFailureNode struct {
|
||||
node *domain.WorkflowNode
|
||||
*nodeLogger
|
||||
}
|
||||
|
||||
func NewExecuteFailureNode(node *domain.WorkflowNode) *executeFailureNode {
|
||||
return &executeFailureNode{
|
||||
node: node,
|
||||
nodeLogger: NewNodeLogger(node),
|
||||
}
|
||||
}
|
||||
|
||||
func (e *executeFailureNode) Run(ctx context.Context) error {
|
||||
e.AddOutput(ctx,
|
||||
e.node.Name,
|
||||
"进入执行失败分支",
|
||||
)
|
||||
return nil
|
||||
}
|
27
internal/workflow/node-processor/execute_success_node.go
Normal file
27
internal/workflow/node-processor/execute_success_node.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package nodeprocessor
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/usual2970/certimate/internal/domain"
|
||||
)
|
||||
|
||||
type executeSuccessNode struct {
|
||||
node *domain.WorkflowNode
|
||||
*nodeLogger
|
||||
}
|
||||
|
||||
func NewExecuteSuccessNode(node *domain.WorkflowNode) *executeSuccessNode {
|
||||
return &executeSuccessNode{
|
||||
node: node,
|
||||
nodeLogger: NewNodeLogger(node),
|
||||
}
|
||||
}
|
||||
|
||||
func (e *executeSuccessNode) Run(ctx context.Context) error {
|
||||
e.AddOutput(ctx,
|
||||
e.node.Name,
|
||||
"进入执行成功分支",
|
||||
)
|
||||
return nil
|
||||
}
|
@@ -57,6 +57,10 @@ func GetProcessor(node *domain.WorkflowNode) (nodeProcessor, error) {
|
||||
return NewDeployNode(node), nil
|
||||
case domain.WorkflowNodeTypeNotify:
|
||||
return NewNotifyNode(node), nil
|
||||
case domain.WorkflowNodeTypeExecuteSuccess:
|
||||
return NewExecuteSuccessNode(node), nil
|
||||
case domain.WorkflowNodeTypeExecuteFailure:
|
||||
return NewExecuteFailureNode(node), nil
|
||||
}
|
||||
return nil, errors.New("not implemented")
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ func (w *workflowProcessor) Run(ctx context.Context) error {
|
||||
func (w *workflowProcessor) runNode(ctx context.Context, node *domain.WorkflowNode) error {
|
||||
current := node
|
||||
for current != nil {
|
||||
if current.Type == domain.WorkflowNodeTypeBranch {
|
||||
if current.Type == domain.WorkflowNodeTypeBranch || current.Type == domain.WorkflowNodeTypeExecuteResultBranch {
|
||||
for _, branch := range current.Branches {
|
||||
if err := w.runNode(ctx, &branch); err != nil {
|
||||
continue
|
||||
@@ -38,24 +38,37 @@ func (w *workflowProcessor) runNode(ctx context.Context, node *domain.WorkflowNo
|
||||
}
|
||||
}
|
||||
|
||||
if current.Type != domain.WorkflowNodeTypeBranch {
|
||||
processor, err := GetProcessor(current)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var runErr error
|
||||
var processor nodeProcessor
|
||||
for {
|
||||
if current.Type != domain.WorkflowNodeTypeBranch && current.Type != domain.WorkflowNodeTypeExecuteResultBranch {
|
||||
processor, runErr = GetProcessor(current)
|
||||
if runErr != nil {
|
||||
break
|
||||
}
|
||||
|
||||
err = processor.Run(ctx)
|
||||
runErr = processor.Run(ctx)
|
||||
|
||||
log := processor.Log(ctx)
|
||||
if log != nil {
|
||||
w.logs = append(w.logs, *log)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
log := processor.Log(ctx)
|
||||
if log != nil {
|
||||
w.logs = append(w.logs, *log)
|
||||
}
|
||||
if runErr != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if runErr != nil && current.Next != nil && current.Next.Type != domain.WorkflowNodeTypeExecuteResultBranch {
|
||||
return runErr
|
||||
} else if runErr != nil && current.Next != nil && current.Next.Type == domain.WorkflowNodeTypeExecuteResultBranch {
|
||||
current = getBranchByType(current.Next.Branches, domain.WorkflowNodeTypeExecuteFailure)
|
||||
} else if runErr == nil && current.Next != nil && current.Next.Type == domain.WorkflowNodeTypeExecuteResultBranch {
|
||||
current = getBranchByType(current.Next.Branches, domain.WorkflowNodeTypeExecuteSuccess)
|
||||
} else {
|
||||
current = current.Next
|
||||
}
|
||||
current = current.Next
|
||||
|
||||
}
|
||||
return nil
|
||||
@@ -68,3 +81,12 @@ func WithWorkflowId(ctx context.Context, id string) context.Context {
|
||||
func GetWorkflowId(ctx context.Context) string {
|
||||
return ctx.Value("workflow_id").(string)
|
||||
}
|
||||
|
||||
func getBranchByType(branches []domain.WorkflowNode, nodeType domain.WorkflowNodeType) *domain.WorkflowNode {
|
||||
for _, branch := range branches {
|
||||
if branch.Type == nodeType {
|
||||
return &branch
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user