The bucket publish-queue listed and reread itself before each send; its items now ride the builder's work queue publishes, pulled per holder and class by consumers the builder makes as it learns a holder, the live class first, a failed send handed back with the pause, an item acknowledged when its publish is heard and terminated when its build is withdrawn, superseded or dropped. builder_publish_drop and builder_publish_first act through reasks after the hand-act log; builder_publish_queue reads the queue through the runtime. The old state's items are moved once at the start, then dropped through the bus module. Builds: design 47 H2 §793, §820; H-A-290, H-A-291, H-A-440, H-A-446 (2), H-A-448
99 lines
4.2 KiB
Go
99 lines
4.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/gopackageregistry"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/process"
|
|
|
|
"mesh-delivery-builder/internal/versions"
|
|
)
|
|
|
|
// The builder's publish again (design 47 G §588, A-73, A-76): the wiring of versions.Republisher to the bus.
|
|
|
|
// entryVia reads a catalog graph entry by its fingerprint through the seat mesh-catalog's verb entry.
|
|
func entryVia(call toolCaller) func(ctx context.Context, fingerprint string) (meshcatalog.CatalogEntry, error) {
|
|
return func(ctx context.Context, fingerprint string) (meshcatalog.CatalogEntry, error) {
|
|
raw, err := callWithin(ctx, call, "seat:"+meshcatalog.Seat+"."+meshcatalog.VerbEntry, meshcatalog.EntryInput{Fingerprint: fingerprint})
|
|
if err != nil {
|
|
return meshcatalog.CatalogEntry{}, err
|
|
}
|
|
var a meshcatalog.EntryAnswer
|
|
if err := json.Unmarshal(raw, &a); err != nil {
|
|
return meshcatalog.CatalogEntry{}, fmt.Errorf("the catalog answered what is no entry: %w", err)
|
|
}
|
|
return a.Entry, nil
|
|
}
|
|
}
|
|
|
|
// keptCaller is a kept call carrying an ask id (process.Conn.CallKeptAsk).
|
|
type keptCaller func(ask process.KeptAsk, key string, body any) (json.RawMessage, error)
|
|
|
|
// publishAskID is the ask id of p's publish (design 47 H2 §775): the same seat, name, version and digest make the same id,
|
|
// so a publish made again is one the holder takes once (ADR 0668 §2); an id holds no dot, as every ask id.
|
|
func publishAskID(p versions.Publish) string {
|
|
sum := sha256.Sum256([]byte(p.Seat + "\n" + p.Name + "\n" + p.Version + "\n" + p.Digest))
|
|
return "publish" + hex.EncodeToString(sum[:8])
|
|
}
|
|
|
|
// sendVia sends a publish to the registry seat with the digest and no parts (A-73): the holder takes the bytes from the
|
|
// artifact store, addressed by digest. The four seats' publish take one wire form; an answer that lacks parts, or a fault of
|
|
// the call, is the holder's refusal, said in its words (not stored when the holder lacks the bytes). The publish is a kept
|
|
// call carrying its ask id (design 47 H2 §775), made again through transport faults at the kept-call pace within ctx's bound.
|
|
func sendVia(call keptCaller) func(ctx context.Context, p versions.Publish) error {
|
|
return func(ctx context.Context, p versions.Publish) error {
|
|
ask := process.KeptAsk{ID: publishAskID(p)}
|
|
if d, ok := ctx.Deadline(); ok {
|
|
ask.Bound = time.Until(d)
|
|
}
|
|
raw, err := callWithin(ctx, func(key string, body any) (json.RawMessage, error) { return call(ask, key, body) },
|
|
"seat:"+p.Seat+"."+versions.VerbPublish, publishBody(p))
|
|
if err != nil {
|
|
return fmt.Errorf("%s's publish of %s %s: %w", p.Seat, p.Name, p.Version, err)
|
|
}
|
|
var a gopackageregistry.PublishAnswer
|
|
if err := json.Unmarshal(raw, &a); err != nil {
|
|
return fmt.Errorf("%s answered what is no publish answer: %w", p.Seat, err)
|
|
}
|
|
if len(a.Lacks) > 0 {
|
|
return fmt.Errorf("%s%s holds %d of the parts of %s %s", versions.NotStoredWords, p.Seat, len(a.Lacks), p.Name, p.Version)
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// callWithin is call within ctx's bound (design 47 H H-A-290 (4)): its answer, or, once the bound ends first, that it was not
|
|
// answered within it. The call itself ends by its own bound (the SDK's call timeout), its answer then dropped.
|
|
func callWithin(ctx context.Context, call toolCaller, key string, body any) (json.RawMessage, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, fmt.Errorf("%s is not called: %w", key, context.Cause(ctx))
|
|
}
|
|
type answer struct {
|
|
raw json.RawMessage
|
|
err error
|
|
}
|
|
done := make(chan answer, 1)
|
|
go func() {
|
|
raw, err := call(key, body)
|
|
done <- answer{raw, err}
|
|
}()
|
|
select {
|
|
case a := <-done:
|
|
return a.raw, a.err
|
|
case <-ctx.Done():
|
|
return nil, fmt.Errorf("%s is not answered within its bound: %w", key, context.Cause(ctx))
|
|
}
|
|
}
|
|
|
|
// publishBody is the seat's publish input for p: the digest, its kind and name and version, no parts.
|
|
func publishBody(p versions.Publish) gopackageregistry.PublishInput {
|
|
return gopackageregistry.PublishInput{Commit: p.Commit, Digest: p.Digest, Fingerprint: p.Fingerprint, Kind: p.Kind, Name: p.Name, Transfer: p.Transfer, Version: p.Version}
|
|
}
|