54 lines
2.4 KiB
Go
54 lines
2.4 KiB
Go
// Package witness is the node-engine watching a core build it placed — the node tools on every machine — and
|
|
// restoring the build before it when the new one is not healthy in bound (novox/hq to-be 45 §8, ADR 0227 rule 8: the
|
|
// component being replaced is never the only witness of its successor).
|
|
//
|
|
// **The contract is this file.** What the engine reads to call a build healthy, from where, in what
|
|
// shape, within which bound — said once, here, and held by contract_test.go.
|
|
package witness
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/novox/mesh-host/internal/compose/resolution"
|
|
"github.com/novox/mesh-host/internal/link"
|
|
)
|
|
|
|
// The witnesses, as a process declares which watches it (`witness`). A process that says none is placed as ever; one
|
|
// that says nothing is judged by its name's default (Default).
|
|
const (
|
|
// ByPing: healthy when this machine's runtime answers the services protocol's PING.
|
|
ByPing = "ping"
|
|
// ByNone: not judged.
|
|
ByNone = "none"
|
|
)
|
|
|
|
// Bounds (to-be 45 §8). A build is given Within of time the witness could ask in; asked every Every.
|
|
const (
|
|
// NodeToolsWithin: the runtime is announced and answering within sixty seconds of starting,
|
|
// each PING answered within PingWithin.
|
|
NodeToolsWithin = 60 * time.Second
|
|
PingWithin = 5 * time.Second
|
|
Every = 5 * time.Second
|
|
// GiveUp is how long a witness goes on when it cannot ask at all before it says the build is
|
|
// unwitnessed: the grant missing, the bus away the whole time.
|
|
GiveUp = 30 * time.Minute
|
|
)
|
|
|
|
// Default is the witness a process is judged by when it names none: the tool runner's process, the core process the mesh
|
|
// composes on every machine for the module whose manifest says it is the tool runner (catalogue.IsToolRunner), with the id
|
|
// `<its module>.runtime` and named as its module (resolution's runtime process), and nothing else. It is pinged by that
|
|
// name on this machine's instance, `$SRV.PING.<name>.<node>`, so only this machine's runtime answers; never known here by
|
|
// a module's name (ADR 0601 §4).
|
|
func Default(id, process string) string {
|
|
if process != "" && id == process+"."+resolution.RuntimeProcessID() {
|
|
return ByPing
|
|
}
|
|
return ByNone
|
|
}
|
|
|
|
// Within is the bound for a witness.
|
|
func Within(string) time.Duration { return NodeToolsWithin }
|
|
|
|
// Component names what a witness judges, as a rollback says it.
|
|
func Component(string) string { return link.ComponentNodeTools }
|