[ Agent ] [ Executor ] - 修改底层执行返回逻辑

This commit is contained in:
zeaslity
2023-11-07 15:53:38 +08:00
parent 4c9a568086
commit dc5ab043fb
3 changed files with 13 additions and 38 deletions

View File

@@ -24,12 +24,12 @@ var log = logger2.Log
var AgentOsOperatorCache = &AgentOsOperator{}
func Execute(em *ExecutionMessage) ([]string, error) {
func Execute(em *ExecutionMessage) (bool, []string) {
var resultLog []string
var err error
var realCommand [][]string
ok := true
executionContent := em.ExecutionType + "==" + strings.Join(em.FuncContent, "")
log.DebugF("em message is => %#v", em)
@@ -40,9 +40,6 @@ func Execute(em *ExecutionMessage) ([]string, error) {
} else {
ok, resultLog = AgentOsOperatorCache.Exec(em.FuncContent[0])
}
if ok {
return resultLog, nil
}
} else if strings.HasPrefix(em.ExecutionType, "APP") {
// app function
@@ -51,39 +48,35 @@ func Execute(em *ExecutionMessage) ([]string, error) {
} else {
ok, resultLog = AgentOsOperatorCache.Deploy(em.FuncContent[0])
}
if ok {
return resultLog, nil
} else {
return resultLog, nil
}
} else {
// shell command
if em.PipeLineCommand != nil && len(em.PipeLineCommand) != 0 {
// 管道命令
resultLog, err = PipeLineCommandExecutor(em.PipeLineCommand)
realCommand = em.PipeLineCommand
executionContent = fmt.Sprintf("%v", em.PipeLineCommand)
} else if em.MultiLineCommand != nil && len(em.MultiLineCommand) != 0 {
// 多行命令
resultLog, err = MultiLineCommandExecutor(em.MultiLineCommand)
realCommand = em.MultiLineCommand
executionContent = fmt.Sprintf("%v", em.MultiLineCommand)
} else {
// 单行命令
resultLog, err = FormatAllCommandExecutor(em.SingleLineCommand)
realCommand = [][]string{em.SingleLineCommand}
executionContent = fmt.Sprintf("%v", em.SingleLineCommand)
}
}
// 归一化错误和日志
if err != nil {
resultLog = append(resultLog, "↓↓↓ 命令 Error 如下 ↓↓↓", err.Error())
resultLog = append(resultLog, " 命令执行错误如下 ", err.Error())
}
resultLog = append(resultLog, fmt.Sprintf("命令 %s 执行结果为 %b", executionContent, ok))
// debug
commandResult := fmt.Sprintf("Excution Comand are=> %v, Executor Result: %v", realCommand, resultLog)
log.Debug(commandResult)
log.DebugF("%v", resultLog)
return resultLog, err
return ok, resultLog
}
func PipeLineCommandExecutor(pipeLineCommand [][]string) ([]string, error) {

View File

@@ -131,8 +131,8 @@ func executorOMHandler(octopusMessage *OctopusMessage) {
}
// 执行命令
resultLog, err := executor.Execute(executionMessage)
if err == nil {
ok, resultLog := executor.Execute(executionMessage)
if ok {
octopusMessage.ResultCode = "200"
} else {
octopusMessage.ResultCode = "300"