feat: opt exec log

This commit is contained in:
engigu
2026-01-01 14:42:33 +08:00
parent 4dfd45ec69
commit 756ba1e0ea
9 changed files with 115 additions and 30 deletions
+11 -9
View File
@@ -52,15 +52,17 @@ func (Task) TableName() string {
// TaskLog represents a log entry for task execution
type TaskLog struct {
ID uint `json:"id" gorm:"primaryKey"`
TaskID uint `json:"task_id" gorm:"index"`
AgentID *uint `json:"agent_id" gorm:"index"` // Agent ID,为空表示本地执行
Command string `json:"command" gorm:"type:text"`
Output string `json:"-" gorm:"type:longtext"` // gzip+base64 compressed
Status string `json:"status" gorm:"size:20"` // success, failed
Duration int64 `json:"duration"` // milliseconds
ExitCode int `json:"exit_code"`
CreatedAt LocalTime `json:"created_at"`
ID uint `json:"id" gorm:"primaryKey"`
TaskID uint `json:"task_id" gorm:"index"`
AgentID *uint `json:"agent_id" gorm:"index"` // Agent ID,为空表示本地执行
Command string `json:"command" gorm:"type:text"`
Output string `json:"-" gorm:"type:longtext"` // gzip+base64 compressed
Status string `json:"status" gorm:"size:20"` // success, failed
Duration int64 `json:"duration"` // milliseconds
ExitCode int `json:"exit_code"`
StartTime *LocalTime `json:"start_time"`
EndTime *LocalTime `json:"end_time"`
CreatedAt LocalTime `json:"created_at"`
}
func (TaskLog) TableName() string {
+10
View File
@@ -339,6 +339,16 @@ func (s *AgentService) ReportResult(result *models.AgentTaskResult) error {
ExitCode: result.ExitCode,
}
// 处理开始和结束时间
if result.StartTime > 0 {
startTime := models.LocalTime(time.Unix(result.StartTime, 0))
taskLog.StartTime = &startTime
}
if result.EndTime > 0 {
endTime := models.LocalTime(time.Unix(result.EndTime, 0))
taskLog.EndTime = &endTime
}
if err := database.DB.Create(taskLog).Error; err != nil {
return err
}
+10 -5
View File
@@ -195,12 +195,17 @@ func (es *ExecutorService) saveTaskLogCallback(taskID uint, command string, resu
status = "failed"
}
startTime := models.LocalTime(result.Start)
endTime := models.LocalTime(result.End)
taskLog := &models.TaskLog{
TaskID: taskID,
Command: command,
Output: compressed,
Status: status,
Duration: result.End.Sub(result.Start).Milliseconds(),
TaskID: taskID,
Command: command,
Output: compressed,
Status: status,
Duration: result.End.Sub(result.Start).Milliseconds(),
StartTime: &startTime,
EndTime: &endTime,
}
if err := database.DB.Create(taskLog).Error; err != nil {