collector/redfish: expand endpoint coverage and timestamp collect logs

This commit is contained in:
2026-02-28 12:59:57 +03:00
parent 9aadf2f1e9
commit 6c19a58b24
3 changed files with 396 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ package server
import (
"context"
"fmt"
"sync"
"time"
)
@@ -23,7 +24,7 @@ func (m *JobManager) CreateJob(req CollectRequest) *Job {
ID: generateJobID(),
Status: CollectStatusQueued,
Progress: 0,
Logs: []string{"Задача поставлена в очередь"},
Logs: []string{formatCollectLogLine(now, "Задача поставлена в очередь")},
CreatedAt: now,
UpdatedAt: now,
RequestMeta: CollectRequestMeta{
@@ -65,7 +66,7 @@ func (m *JobManager) CancelJob(id string) (*Job, bool) {
job.Status = CollectStatusCanceled
job.Error = ""
job.UpdatedAt = time.Now().UTC()
job.Logs = append(job.Logs, "Сбор отменен пользователем")
job.Logs = append(job.Logs, formatCollectLogLine(job.UpdatedAt, "Сбор отменен пользователем"))
}
cancelFn := job.cancel
@@ -120,6 +121,7 @@ func (m *JobManager) AppendJobLog(id, message string) (*Job, bool) {
job.Logs = append(job.Logs, message)
job.UpdatedAt = time.Now().UTC()
job.Logs[len(job.Logs)-1] = formatCollectLogLine(job.UpdatedAt, message)
cloned := cloneJob(job)
m.mu.Unlock()
@@ -157,6 +159,17 @@ func normalizeProgress(progress int) int {
return progress
}
func formatCollectLogLine(ts time.Time, message string) string {
msg := message
if msg == "" {
msg = "-"
}
if ts.IsZero() {
ts = time.Now().UTC()
}
return fmt.Sprintf("%s %s", ts.Format(time.RFC3339Nano), msg)
}
func cloneJob(job *Job) *Job {
if job == nil {
return nil