[agent-go] 调整代码结构

This commit is contained in:
zeaslity
2023-03-30 14:26:11 +08:00
parent b01eb57ee5
commit 124143c6c6
17 changed files with 622 additions and 594 deletions

View File

@@ -1,31 +1,43 @@
package executor
import (
"agent-go/config"
"agent-go/g"
logger2 "agent-go/logger"
"bufio"
"bytes"
"fmt"
"os/exec"
"time"
)
var log = g.G.LOG
type ExecutionMessage struct {
NeedResultReplay bool `json:"needResultReplay"`
DurationTask bool `json:"durationTask,default:false"`
Type string `json:"type"`
SingleLineCommand []string `json:"singleLineCommand"`
MultiLineCommand [][]string `json:"multiLineCommand"`
PipeLineCommand [][]string `json:"pipeLineCommand"`
ResultKey string `json:"resultKey"`
}
func Execute(om *config.OctopusMessage, em *config.ExecutionMessage) ([]string, error) {
var log = logger2.Log
func Execute(em *ExecutionMessage) ([]string, error) {
var resultLog []string
var err error
var realCommand [][]string
if em.PipeLineCommand != nil && len(em.PipeLineCommand) != 0 {
// 管道命令
resultLog, err = PipeLineCommandExecutor(em.PipeLineCommand)
realCommand = em.PipeLineCommand
} else if em.MultiLineCommand != nil && len(em.MultiLineCommand) != 0 {
// 多行命令
resultLog, err = MultiLineCommandExecutor(em.MultiLineCommand)
realCommand = em.MultiLineCommand
} else {
// 单行命令
resultLog, err = SingleLineCommandExecutor(em.SingleLineCommand)
realCommand = [][]string{em.SingleLineCommand}
}
// 归一化错误和日志
@@ -33,15 +45,9 @@ func Execute(om *config.OctopusMessage, em *config.ExecutionMessage) ([]string,
resultLog = append(resultLog, fmt.Sprintf("Error: %s", err.Error()))
}
// 处理执行日志
// 是否需要返回处理日志,现在默认返回
if em.NeedResultReplay {
// 需要返回处理结果
om.ACTime = time.Now()
om.Result = resultLog
}
commandResult := fmt.Sprintf("Excution Comand are=> %v, Executor Result: %v", realCommand, resultLog)
log.Info(fmt.Sprintf("Executor Result: %s", resultLog))
log.Info(commandResult)
return resultLog, err
}