Files
core/http/api/report.go
Ingo Oppermann 4ce8a0eaa3 Add config value for how many minimal process report should be kept in the history
A minimal history is a history entry without log and prelude.

The corresponding config entry is ffmpeg.log.max_minimal_history. This value is
added on top of the ffmpeg.log.max_history value. I.e. the latest max_history
entries contain the log and prelude, and the remaining entries don't have the
log and prelude. In total there are max_minimal_history+max_history history
entries.

If you want no history, set both values to 0.
If you want only full history, set max_minimal_history to 0.
If you want only minimal history, set max_history to 0.
2023-03-16 12:25:06 +01:00

75 lines
1.9 KiB
Go

package api
import (
"strconv"
"github.com/datarhei/core/v16/restream/app"
)
// ProcessReportEntry represents the logs of a run of a restream process
type ProcessReportEntry struct {
CreatedAt int64 `json:"created_at" format:"int64"`
Prelude []string `json:"prelude,omitempty"`
Log [][2]string `json:"log,omitempty"`
}
type ProcessReportHistoryEntry struct {
ProcessReportEntry
ExitedAt int64 `json:"exited_at" format:"int64"`
ExitState string `json:"exit_state"`
Progress Progress `json:"progress"`
}
// ProcessReport represents the current log and the logs of previous runs of a restream process
type ProcessReport struct {
ProcessReportEntry
History []ProcessReportHistoryEntry `json:"history"`
}
// Unmarshal converts a restream log to a report
func (report *ProcessReport) Unmarshal(l *app.Log) {
if l == nil {
return
}
report.CreatedAt = l.CreatedAt.Unix()
report.Prelude = l.Prelude
report.Log = make([][2]string, len(l.Log))
for i, line := range l.Log {
report.Log[i][0] = strconv.FormatInt(line.Timestamp.Unix(), 10)
report.Log[i][1] = line.Data
}
report.History = []ProcessReportHistoryEntry{}
for _, h := range l.History {
he := ProcessReportHistoryEntry{
ProcessReportEntry: ProcessReportEntry{
CreatedAt: h.CreatedAt.Unix(),
Prelude: h.Prelude,
Log: make([][2]string, len(h.Log)),
},
ExitedAt: h.ExitedAt.Unix(),
ExitState: h.ExitState,
}
he.Progress.Unmarshal(&h.Progress)
for i, line := range h.Log {
he.ProcessReportEntry.Log[i][0] = strconv.FormatInt(line.Timestamp.Unix(), 10)
he.ProcessReportEntry.Log[i][1] = line.Data
}
report.History = append(report.History, he)
}
}
type ProcessReportSearchResult struct {
ProcessID string `json:"id"`
Reference string `json:"reference"`
ExitState string `json:"exit_state"`
CreatedAt int64 `json:"created_at" format:"int64"`
ExitedAt int64 `json:"exited_at" format:"int64"`
}