mirror of
https://github.com/datarhei/core.git
synced 2025-10-05 16:07:07 +08:00
Add process report API
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user