diff --git a/automation/server/internal/module/job_history/model/job.go b/automation/server/internal/module/job_history/model/job.go index 84e0ec9c6dc160f086679a45dd8ef272fa1e142a..4f37a01535cd64e65961edcc9023b1525306ce12 100644 --- a/automation/server/internal/module/job_history/model/job.go +++ b/automation/server/internal/module/job_history/model/job.go @@ -2,7 +2,6 @@ package model import ( "encoding/json" - "fmt" "openeuler.org/PilotGo/PilotGo-plugin-automation/internal/module/common/enum/workflow" ) @@ -82,7 +81,6 @@ type SubJobStepResult struct { StartTime string `json:"start_time" gorm:"comment:开始执行时间"` EndTime string `json:"end_time" gorm:"comment:结束时间"` Result json.RawMessage `json:"result" gorm:"type:json;comment:步骤执行结果"` - ParsedResult Result `json:"-" gorm:"-"` } type Result struct { @@ -91,26 +89,6 @@ type Result struct { Message string `json:"message"` } -func (s *SubJobStepResult) UnmarshalJSON(data []byte) error { - type Alias SubJobStepResult - temp := &struct { - *Alias - }{} - - temp.Alias = (*Alias)(s) - - if err := json.Unmarshal(data, temp); err != nil { - return err - } - - if len(s.Result) > 0 { - if err := json.Unmarshal(s.Result, &s.ParsedResult); err != nil { - fmt.Printf("警告: 解析Result字段失败: %v\n", err) - } - } - return nil -} - type JobDTO struct { Job Job `json:"job"` InputParams []JobParams `json:"input_params"` diff --git a/automation/server/internal/module/job_history/service/job.go b/automation/server/internal/module/job_history/service/job.go index 4a8882b2be17b8354976c24b07a44454d9582ad0..d1998a83bf3c46883fe36c9630ac6033734e931d 100644 --- a/automation/server/internal/module/job_history/service/job.go +++ b/automation/server/internal/module/job_history/service/job.go @@ -1,6 +1,7 @@ package service import ( + "encoding/json" "fmt" "strings" "time" @@ -77,6 +78,13 @@ func GetSubJobResultByJobId(jobId, ip string) (interface{}, error) { return nil, fmt.Errorf("获取%s stepNum=%v 结果失败: jobId=%s, err=%v", ip, subJobResult.CurrentStep, jobId, err.Error()) } + var result model.Result + if len(currentStepResult.Result) > 0 { + if err := json.Unmarshal(currentStepResult.Result, &result); err != nil { + return nil, fmt.Errorf("解析 stepNum=%v Result字段失败: jobId=%s, err=%v", subJobResult.CurrentStep, jobId, err.Error()) + } + } + resultMap := make(map[string]interface{}) resultMap["id"] = subJobResult.ID resultMap["job_id"] = subJobResult.JobId @@ -88,7 +96,7 @@ func GetSubJobResultByJobId(jobId, ip string) (interface{}, error) { resultMap["start_time"] = subJobResult.StartTime resultMap["end_time"] = subJobResult.EndTime resultMap["results"] = stepResults - resultMap["message"] = currentStepResult.ParsedResult.Stdout + resultMap["message"] = result.Stdout return resultMap, nil } diff --git a/automation/server/internal/service/mysql.go b/automation/server/internal/service/mysql.go index bed8acd62004e932693668e059f8fecaa9c32395..4387bcef5923000b11cb1cc4426b0d16041aa75f 100644 --- a/automation/server/internal/service/mysql.go +++ b/automation/server/internal/service/mysql.go @@ -2,6 +2,7 @@ package service import ( "fmt" + "time" "gorm.io/driver/mysql" "gorm.io/gorm" @@ -44,6 +45,15 @@ func (m *MySQLService) Init(ctx *AppContext) error { return err } + sqlDB, err := db.DB() + if err != nil { + return err + } + sqlDB.SetMaxOpenConns(20) // 最大连接数 + sqlDB.SetMaxIdleConns(10) // 最大空闲连接数 + sqlDB.SetConnMaxLifetime(time.Hour) // 连接生命周期 + sqlDB.SetConnMaxIdleTime(30 * time.Minute) + db.AutoMigrate(&dangerousRule.DangerousRule{}) db.AutoMigrate(&scriptLibrary.Tag{}) db.AutoMigrate(&scriptLibrary.Script{})