all: Propagate errors from NamespacedKV (#6203)

As foretold by the prophecy, "once the database refactor is merged, then
shall appear a request to propagate errors from the store known
throughout the land as the NamedspacedKV, and it shall be good".
This commit is contained in:
Jakob Borg
2019-11-30 13:03:24 +01:00
committed by GitHub
parent 928767e316
commit e82a7e3dfa
12 changed files with 210 additions and 98 deletions

View File

@@ -28,24 +28,30 @@ func NewDeviceStatisticsReference(ldb *db.Lowlevel, device string) *DeviceStatis
}
}
func (s *DeviceStatisticsReference) GetLastSeen() time.Time {
t, ok := s.ns.Time("lastSeen")
if !ok {
func (s *DeviceStatisticsReference) GetLastSeen() (time.Time, error) {
t, ok, err := s.ns.Time("lastSeen")
if err != nil {
return time.Time{}, err
} else if !ok {
// The default here is 1970-01-01 as opposed to the default
// time.Time{} from s.ns
return time.Unix(0, 0)
return time.Unix(0, 0), nil
}
l.Debugln("stats.DeviceStatisticsReference.GetLastSeen:", s.device, t)
return t
return t, nil
}
func (s *DeviceStatisticsReference) WasSeen() {
func (s *DeviceStatisticsReference) WasSeen() error {
l.Debugln("stats.DeviceStatisticsReference.WasSeen:", s.device)
s.ns.PutTime("lastSeen", time.Now())
return s.ns.PutTime("lastSeen", time.Now())
}
func (s *DeviceStatisticsReference) GetStatistics() DeviceStatistics {
return DeviceStatistics{
LastSeen: s.GetLastSeen(),
func (s *DeviceStatisticsReference) GetStatistics() (DeviceStatistics, error) {
lastSeen, err := s.GetLastSeen()
if err != nil {
return DeviceStatistics{}, err
}
return DeviceStatistics{
LastSeen: lastSeen,
}, nil
}