nats: the tools bundle answers initialize again (keep days read when asked)
bundleKeepDays read the config value snapshot-keep-days while allTools listed the tools, before stdio.Serve; a config read waits for the runtime's channel, which opens only once the bundle serves, so the bundle never answered initialize and node-tools served none of its tools (novox 2026-11-16 22:21 and 22:26, after the first build from main since A-112). The setting is now read when nats_snapshots is called.
This commit is contained in:
@@ -197,13 +197,15 @@ func allTools() []stdio.Tool {
|
||||
out = append(out, keeperHealthTool(StatusInState, HeldInState, jsz))
|
||||
out = append(out, readTools(jsz, LiveMsgGet(LiveBus()))...)
|
||||
rs := RequestsInState()
|
||||
out = append(out, snapshotListTool(rs, bundleKeepDays())...)
|
||||
out = append(out, snapshotListTool(rs, bundleKeepDays)...)
|
||||
out = append(out, plansTool(PlansInState))
|
||||
return append(out, requestTools(rs)...)
|
||||
}
|
||||
|
||||
// bundleKeepDays is the setting snapshot-keep-days as this bundle's configuration holds it (design 47 G A-112), its
|
||||
// default when the runtime gives none.
|
||||
// default when the runtime gives none. It is read when a tool asks, never while the tools are listed: a config read
|
||||
// waits for the runtime's channel, which opens only once the bundle serves, so a read before Serve never returns and
|
||||
// the bundle never answers initialize.
|
||||
func bundleKeepDays() int {
|
||||
if raw, err := stdio.Config("snapshot-keep-days"); err == nil {
|
||||
var n int
|
||||
|
||||
@@ -324,7 +324,7 @@ func heldRequest(store keeper.Store) func(id string) (*keeper.Request, error) {
|
||||
}
|
||||
|
||||
// snapshotListTool is nats_snapshots, which the tools bundle keeps beside the verbs the keeper's process answers.
|
||||
func snapshotListTool(rs requestStore, keepDays int) []stdio.Tool {
|
||||
func snapshotListTool(rs requestStore, keepDays func() int) []stdio.Tool {
|
||||
return []stdio.Tool{
|
||||
{Name: "nats_snapshots",
|
||||
Description: "The keeper's snapshots of kept data taken before a drop or recreate, from its state requests: each one's request, module, local name, stream, size, digest, time, whether it is protected (restored only in place, never sent), whether it is expired (past snapshot-keep-days, removed at the keeper's next request) and whether it is recorded (a snapshot of before milestone G holds no digest and is sent or removed by hand only).",
|
||||
@@ -344,7 +344,7 @@ func snapshotListTool(rs requestStore, keepDays int) []stdio.Tool {
|
||||
continue
|
||||
}
|
||||
out = append(out, map[string]any{"request": r.ID, "module": r.Module, "local": r.Local, "stream": keeper.BusName(r.Module, r.Local),
|
||||
"size": r.Size, "digest": r.Digest, "at": r.At, "protected": r.Protected, "expired": r.Expired(rs.Now(), keepDays), "recorded": r.Recorded()})
|
||||
"size": r.Size, "digest": r.Digest, "at": r.At, "protected": r.Protected, "expired": r.Expired(rs.Now(), keepDays()), "recorded": r.Recorded()})
|
||||
}
|
||||
return map[string]any{"snapshots": out}, nil
|
||||
}},
|
||||
|
||||
@@ -222,7 +222,7 @@ func TestTheKeepersProcessAnswersTheSnapshotVerbs(t *testing.T) {
|
||||
t.Errorf("the hand acts %v: the caller of a call that named none is %s", acts, stdio.Unproven)
|
||||
}
|
||||
// nats_snapshots lists every snapshot, the expired and the unrecorded said.
|
||||
out, err = snapshotListTool(rs, 90)[0].Run(nil)
|
||||
out, err = snapshotListTool(rs, func() int { return 90 })[0].Run(nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user