The keeper reads pacman's database into installed.<node> and writes it only when it differs from the key, says each change as package.changed, and keeps the last value when the list is over the bus's cap, marking the node not current until it fits again; the health names the size. The loop runs over injected states, events, clock, watch and machine, and leaves hooks (start, after a transaction, state watches, wakes) for the upgrade parts of ADR 0508.
33 lines
1.4 KiB
Go
33 lines
1.4 KiB
Go
package main
|
|
|
|
// A node whose packages are over the bus's cap is unhealthy, naming the size (novox/hq ADR 0507 §2, acceptance
|
|
// 1840/AC3): `installed.<node>` keeps its last value, which is no longer the node's, and the module's health says
|
|
// so until the keeper writes it again and deletes the mark.
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
// InstalledHealth is the health of this node's `installed` key: unhealthy while `<node>.not-current` is there,
|
|
// with its size and since when; ok false when there is nothing to say (the key is current, or the state cannot
|
|
// be read here, which the keeper's own log says).
|
|
func (m *Machine) InstalledHealth() (Health, bool) {
|
|
if m.States == nil || m.Node == "" {
|
|
return Health{}, false
|
|
}
|
|
e, err := m.States(StateInstalled).Get(NotCurrentKey(m.Node))
|
|
if err != nil {
|
|
return Health{Why: "the node's packages on the bus could not be read: " + err.Error()}, true
|
|
}
|
|
if e == nil {
|
|
return Health{}, false
|
|
}
|
|
var nc NotCurrent
|
|
if err := json.Unmarshal(e.Value, &nc); err != nil {
|
|
return Health{Why: fmt.Sprintf("installed.%s is marked not current, and its mark is not readable: %v", m.Node, err)}, true
|
|
}
|
|
return Health{Why: fmt.Sprintf("the node's packages come to %d bytes, over the bus's cap of %d on a value, since %s: "+
|
|
"installed.%s keeps an older list", nc.Bytes, ValueCap, nc.Since.Format("2006-01-02 15:04 MST"), m.Node)}, true
|
|
}
|