The review found §794's two bounds fixed in code: the builder's 100 ms for saying a slow event's handling, and builder_health's five minutes for naming a consumer behind. Both become settings read at run time, slow-event (100ms) and events-behind-bound (5m), declared in the manifest's config with those defaults; a value that is no duration refuses the builder's start, and makes the health say it. Builds: design 47 H2 §794, H-A-461 (2)
41 lines
2.1 KiB
Go
41 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"time"
|
|
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
"git.novox.be/novox/mesh-sdk/go/health"
|
|
|
|
"mesh-delivery-builder/internal/versions"
|
|
)
|
|
|
|
const (
|
|
// HealthTool is builder_health, the builder's health as its manifest's health asks it (design 47 H2 §794, H-A-435).
|
|
HealthTool = "builder_health"
|
|
// eventsBehindBoundSetting is the setting events-behind-bound (§794; H-A-461 (2), P11): how long a durable consumer's
|
|
// oldest unacknowledged message may wait before the health names it, an events backlog or a handler standing still on one
|
|
// message; defaultEventsBehindBound when none is set.
|
|
eventsBehindBoundSetting = "events-behind-bound"
|
|
defaultEventsBehindBound = 5 * time.Minute
|
|
)
|
|
|
|
// healthTool is builder_health: healthy when it answers, and each of the builder's durable consumers' oldest unacknowledged
|
|
// message waits less than the setting events-behind-bound, as the consumers' facts the builder writes at every delivery and
|
|
// every acknowledgement say them (its state consumers, the runner's runner_health form; H-A-435 and its addendum); otherwise
|
|
// unhealthy, naming each consumer behind and how long. A setting that holds no duration is said as the health's answer.
|
|
func healthTool(consumers versions.Reader, now func() time.Time) stdio.Tool {
|
|
return stdio.Tool{Name: HealthTool,
|
|
Description: "The builder's health: healthy when it answers and each of its durable consumers' oldest unacknowledged message waits less " +
|
|
"than the setting events-behind-bound (five minutes by default; no events backlog, no handler standing still on a message); otherwise it " +
|
|
"names each consumer behind and how long. Read from the builder's state consumers, which it writes at every message delivered and " +
|
|
"acknowledged. Read-only.",
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{}},
|
|
Run: func(map[string]any) (any, error) {
|
|
bound, err := stdio.SettingDuration(eventsBehindBoundSetting, defaultEventsBehindBound)
|
|
if err != nil {
|
|
return health.Unhealthy("The builder's " + err.Error() + "."), nil
|
|
}
|
|
return versions.BuilderHealth(consumers, now(), bound), nil
|
|
}}
|
|
}
|