Add process report API

This commit is contained in:
Ingo Oppermann
2023-03-02 11:15:57 +01:00
parent cceb39192a
commit 0dedcddece
10 changed files with 499 additions and 96 deletions

View File

@@ -33,6 +33,10 @@ type Parser interface {
// ReportHistory returns an array of previews logs
ReportHistory() []ReportHistoryEntry
// SearchReportHistory returns a list of CreatedAt dates of reports that match the
// provided state and time range.
SearchReportHistory(state string, from, to *time.Time) []ReportHistorySearchResult
// LastLogline returns the last parsed log line
LastLogline() string
}
@@ -732,6 +736,46 @@ type ReportHistoryEntry struct {
Progress Progress
}
type ReportHistorySearchResult struct {
CreatedAt time.Time
ExitState string
}
func (p *parser) SearchReportHistory(state string, from, to *time.Time) []ReportHistorySearchResult {
result := []ReportHistorySearchResult{}
p.logHistory.Do(func(l interface{}) {
if l == nil {
return
}
e := l.(ReportHistoryEntry)
if len(state) != 0 && state != e.ExitState {
return
}
if from != nil {
if e.CreatedAt.Before(*from) {
return
}
}
if to != nil {
if e.CreatedAt.After(*to) {
return
}
}
result = append(result, ReportHistorySearchResult{
CreatedAt: e.CreatedAt,
ExitState: e.ExitState,
})
})
return result
}
func (p *parser) storeReportHistory(state string) {
if p.logHistory == nil {
return