The delivery repository's contracts and SDK live under modules/ as mesh-delivery-contracts and mesh-delivery-sdk, their Go module paths renamed to match the folders (the TypeScript names already did), and every importer in mesh-delivery, mesh-catalog, mesh-host, mesh-tools and mesh-sdk follows in the same group: a design as it should be, one path per module, checked by the group's check building every importer. Builds: design 47 G §427, §88 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
72 lines
3.3 KiB
Go
72 lines
3.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildimage"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildnode"
|
|
"github.com/novox/mesh-host/internal/apply"
|
|
)
|
|
|
|
// The artifact store's holder takes its own new build from the build node that kept it (design 47): its done build names the
|
|
// node and the digest, the node's build seat answers where the bytes are as an object on the bus, and the node-engine
|
|
// reads them and checks them against the digest. Never another module's files: the seat's verb is the way.
|
|
|
|
// keptAskWithin bounds one ask of a build seat; keptObjectWithin one read of the object.
|
|
var (
|
|
keptAskWithin = 30 * time.Second
|
|
keptObjectWithin = 10 * time.Minute
|
|
)
|
|
|
|
// keptBuildSeats are the three build seats, each of which serves the verb kept-artifact: the node that kept the build
|
|
// holds the seat of the language it was built in, and the others do not answer.
|
|
var keptBuildSeats = []string{nodebuildgo.Seat, nodebuildnode.Seat, nodebuildimage.Seat}
|
|
|
|
// keptArtifactFetch is the apply's fetch of what a module's done build kept on a build node.
|
|
func keptArtifactFetch(buildOf func(context.Context, string, string) (string, string, bool, error),
|
|
ask func(ctx context.Context, node, seat, verb string, args any, within time.Duration) (json.RawMessage, error),
|
|
object func(ctx context.Context, store, name string, limit int64) ([]byte, error)) apply.KeptFetch {
|
|
return func(ctx context.Context, module, digest string) ([]byte, bool, error) {
|
|
node, fp, kept, err := buildOf(ctx, module, digest)
|
|
if err != nil || !kept {
|
|
return nil, false, err
|
|
}
|
|
hex := strings.TrimPrefix(digest, "sha256:")
|
|
var notHeld []string
|
|
for _, seat := range keptBuildSeats {
|
|
raw, err := ask(ctx, node, seat, nodebuildgo.VerbKeptArtifact,
|
|
nodebuildgo.KeptArtifactInput{Module: module, Fp: fp, Digest: hex}, keptAskWithin)
|
|
if err != nil {
|
|
notHeld = append(notHeld, seat+": "+err.Error())
|
|
continue
|
|
}
|
|
var got nodebuildgo.KeptArtifactAnswer
|
|
if json.Unmarshal(raw, &got) != nil {
|
|
return nil, true, fmt.Errorf("%s of %s answered with something that is not an answer of kept-artifact", seat, node)
|
|
}
|
|
switch {
|
|
case got.Error != "":
|
|
return nil, true, fmt.Errorf("%s of %s could not give the kept build of %s: %s", seat, node, module, got.Error)
|
|
case got.Refused != "":
|
|
return nil, true, fmt.Errorf("%s of %s refuses the kept build of %s: %s %s", seat, node, module, got.Refused, got.Words)
|
|
case got.Store == "" || got.Object == "" || got.Digest != hex:
|
|
return nil, true, fmt.Errorf("%s of %s answered for %s without the store and the object of the digest %s", seat, node, module, hex)
|
|
}
|
|
octx, cancel := context.WithTimeout(ctx, keptObjectWithin)
|
|
body, err := object(octx, got.Store, got.Object, got.Size+1)
|
|
cancel()
|
|
if err != nil {
|
|
return nil, true, fmt.Errorf("the build of %s kept on %s could not be read from %s: %w", module, node, got.Store, err)
|
|
}
|
|
return body, true, nil
|
|
}
|
|
return nil, true, fmt.Errorf("%s keeps the build of %s for the artifact store and none of its build seats answers (%s)",
|
|
node, module, strings.Join(notHeld, "; "))
|
|
}
|
|
}
|