nano-run/server/ui/unit_info.go

40 lines
658 B
Go
Raw Normal View History

2020-10-01 13:09:40 +00:00
package ui
import (
"os"
"nano-run/server"
"nano-run/services/meta"
"nano-run/worker"
)
type unitInfo struct {
2020-11-07 15:04:40 +00:00
Unit server.Unit
Worker *worker.Worker
CronEntries []*server.CronEntry
2020-10-01 13:09:40 +00:00
}
type historyRecord struct {
ID string
Meta meta.Request
}
func (info unitInfo) History(max int) ([]historyRecord, error) {
var res []historyRecord
err := info.Worker.Meta().Iterate(func(id string, record meta.Request) error {
if len(res) >= max {
return os.ErrClosed
}
res = append(res, historyRecord{
ID: id,
Meta: record,
})
return nil
})
if err == os.ErrClosed || err == nil {
return res, nil
}
return nil, err
}