Files
mesh-delivery/modules/mesh-delivery-view/viewstate/waits.go
T
jschoubben 06e5980898 VW2: the view's waits are the parts' wait-held, kept in its state waits
The view's process hears wait-held and wait-ended of every part (seats and modules; waits.go, manifest consumes) and keeps them in
its state waits under owner.step.node.module (viewstate/waits.go); view_tiers reads them through the tools bundle and names each
module's waits in the sayer's own words, {owner, step, node, on, bound, since, words} (tiers.go waitsHeld), beside the indexer's
pending revisions as the seat mesh-catalog's step take-in. No state of another module is read for a tier's waits.

Builds: design 47 G §512, §376, §498, A-242
2026-11-12 09:19:18 +01:00

70 lines
2.5 KiB
Go

package viewstate
import (
"bytes"
"encoding/json"
"fmt"
"strings"
"time"
"git.novox.be/novox/mesh-sdk/go/keys"
)
// WaitsState is the view's own state `waits`: every wait a part holds, as the parts say it (design 47 G §512, §376, A-242), one
// key `<owner>.<step>.<node>.<module>` each, written by the view's process when it hears `wait-held` and deleted when it hears
// `wait-ended`, and read by view_tiers through the view's own read tool.
const WaitsState = "waits"
// WaitsBucket is the bus's bucket of the state waits.
const WaitsBucket = ViewModule + "_waits"
// Wait is the value of a waits key: the fields of the seat mesh-wants' wait (§498, §512, §629) as the part that holds it said
// them. The view writes no words of its own: Words is the sayer's.
type Wait struct {
// Owner is the seat or module that says the wait.
Owner string `json:"owner"`
Step string `json:"step"`
Node string `json:"node,omitempty"`
Module string `json:"module,omitempty"`
On string `json:"on,omitempty"`
Bound string `json:"bound,omitempty"`
Since time.Time `json:"since"`
Words string `json:"words,omitempty"`
Reason string `json:"reason,omitempty"`
Part string `json:"part,omitempty"`
Version string `json:"version,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
Machines []string `json:"machines,omitempty"`
}
// WaitKey is the key of a wait: owner, step, node and module, each as a key part (an absent one is `-`).
func WaitKey(owner, step, node, module string) string {
part := func(s string) string {
if s == "" {
return "-"
}
return keys.EscapeName(s)
}
return strings.Join([]string{part(owner), part(step), part(node), part(module)}, ".")
}
// Key is the wait's key.
func (w Wait) Key() string { return WaitKey(w.Owner, w.Step, w.Node, w.Module) }
// ReadWait reads the body of a wait-held or wait-ended said by owner (the seat or module of its subject): the owner is the
// body's own when it names one. A body with no step or a field the wait does not know is refused.
func ReadWait(owner string, body []byte) (Wait, error) {
var w Wait
dec := json.NewDecoder(bytes.NewReader(body))
if err := dec.Decode(&w); err != nil {
return Wait{}, fmt.Errorf("the wait does not read: %w", err)
}
if w.Owner == "" {
w.Owner = owner
}
if w.Step == "" || w.Owner == "" {
return Wait{}, fmt.Errorf("the wait names no step or no owner")
}
return w, nil
}