Files
mesh-delivery/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/readscall.go
T
jschoubben 07c13b0b9c B1 (builder): the builder's own buckets are named from its credential's module
The versions, bounds, reserved, publish-queue, acted, toolchains-heard and instances buckets were constants naming
mesh-delivery-builder; ownBucketsOf takes them from the module the credential names.

Builds: design 47 G A-296, §428

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 23:32:42 +01:00

73 lines
3.0 KiB
Go

package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"time"
"github.com/nats-io/nats.go/jetstream"
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient/enginereads"
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
"git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshwatchdogs"
"mesh-delivery-builder/internal/versions"
)
// presenceInvoke is the watchdogs seat's verb presence as the manifest's invokes names it: whether a node's machine is
// heard, asked of the seat, never read from its holder's state (novox/hq ADR 0596 §2).
const presenceInvoke = "seat:" + meshwatchdogs.Seat + "." + meshwatchdogs.VerbPresence
// heardBy asks the watchdogs seat's presence of one machine through call (process.Conn.CallKept, a read) and reads its
// declared answer: whether the machine is heard now.
func heardBy(call func(key string, body any) (json.RawMessage, error)) func(context.Context, string) (bool, error) {
return func(_ context.Context, machine string) (bool, error) {
raw, err := call(presenceInvoke, meshwatchdogs.PresenceInput{Machine: machine})
if err != nil {
return false, err
}
var a meshwatchdogs.PresenceAnswer
if err := json.Unmarshal(raw, &a); err != nil {
return false, fmt.Errorf("%s does not read: %w", presenceInvoke, err)
}
return a.Online, nil
}
}
// callsOf is the wait of the builder's kept manifest-reads calls (enginereads.ReadsCalls): a node whose engine has not
// answered for five minutes is, when its bound ends and the watchdogs seat says its machine is heard, the finding
// call-unanswered in the builder's findings (issue 1966, ADR 0668 §3); its bound is a key of the state bounds with its
// own time to live.
func (r *engineReads) callsOf(f *findings, bounds func() jetstream.KeyValue, heard func(context.Context, string) (bool, error), logf func(string, ...any)) *enginereads.ReadsCalls {
c := &enginereads.ReadsCalls{Keeper: r.keeper, Nodes: r.named, Heard: heard, Bound: mcc.CallUnansweredAfter, Logf: logf,
Raise: func(ctx context.Context, u enginereads.UnansweredCall) error {
o := callUnanswered(enginereads.CallID(u.Node), enginereads.Invoke, u.Node, u.Words, "builder."+mcc.KindCallUnanswered, u.Since)
o.needs = "builder_engine_reads with ask_again asks the node again now and shows its statement."
f.raise(ctx, o)
return nil
},
Clear: func(ctx context.Context, node string) error {
f.clear(ctx, mcc.KindCallUnanswered, mcc.ScopeCall, enginereads.CallID(node))
return nil
},
Arm: func(ctx context.Context, node string, ends time.Time) error {
kv := bounds()
if kv == nil {
return errors.New(versions.BoundsState + " is not on the bus yet")
}
left := max(time.Until(ends), time.Second)
_, err := kv.Create(ctx, enginereads.BoundPrefix+node, versions.EncodeBound("the manifest-reads call to "+node, ends), jetstream.KeyTTL(left))
if errors.Is(err, jetstream.ErrKeyExists) {
err = nil
}
return err
}}
if f != nil && f.now != nil {
c.Now = f.now
}
r.calls = c
return c
}