Builds: design 47 G §196, §594, §614; lead answers A-5, A-15 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
69 lines
2.6 KiB
Go
69 lines
2.6 KiB
Go
package main
|
|
|
|
// The provisioner's reading of which modules exist and of a provider's manifest (design 47 G §196, §594, §614): the catalog
|
|
// half, taken through meshcatalogclient's follower of the watched branches on the part's one views reader. A module's
|
|
// manifest is the one its catalog graph entry carries whole (§443), never the indexer's state `modules` or `manifests`; the
|
|
// manifest a running build was made from is the entry read by that build's fingerprint (§614, an older build's entry).
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
|
|
catalog "git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
|
|
)
|
|
|
|
// CatalogHalf is what the holder reads of the catalog half.
|
|
type CatalogHalf interface {
|
|
// Entry is a module's entry at the trunk; an error while a watched branch has no first view yet, never "no module".
|
|
Entry(module string) (catalog.CatalogEntry, bool, error)
|
|
// Ready is nil once every watched branch has its first view (none-yet counting as one), else says what it waits for.
|
|
Ready() error
|
|
// ByFingerprint reads an entry by the fingerprint of a build: from a branch's half when one lists it, else asked of the
|
|
// seat's verb `entry` once and kept (asked, answered or not found).
|
|
ByFingerprint(ctx context.Context, fingerprint string) (catalog.CatalogEntry, meshcatalogclient.EntryState)
|
|
}
|
|
|
|
// branchesHalf is the CatalogHalf over the follower of the watched branches.
|
|
type branchesHalf struct{ b *meshcatalogclient.Branches }
|
|
|
|
func (h branchesHalf) Ready() error {
|
|
followed := h.b.Followed()
|
|
if len(followed) == 0 {
|
|
return fmt.Errorf("the catalog half names no watched branch yet (the seat mesh-catalog's registrations are asked until they answer)")
|
|
}
|
|
var waiting []string
|
|
for _, branch := range followed {
|
|
if c, ok := h.b.Catalog(branch); ok {
|
|
select {
|
|
case <-c.Ready():
|
|
default:
|
|
waiting = append(waiting, branch)
|
|
}
|
|
}
|
|
}
|
|
if len(waiting) > 0 {
|
|
return fmt.Errorf("the catalog half has no first view of %s yet", strings.Join(waiting, ", "))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (h branchesHalf) Entry(module string) (catalog.CatalogEntry, bool, error) {
|
|
if err := h.Ready(); err != nil {
|
|
return catalog.CatalogEntry{}, false, err
|
|
}
|
|
for _, branch := range h.b.Followed() { // the branch followed first names a module more than one hold
|
|
if c, ok := h.b.Catalog(branch); ok {
|
|
if e, ok := c.Entry(module); ok {
|
|
return e, true, nil
|
|
}
|
|
}
|
|
}
|
|
return catalog.CatalogEntry{}, false, nil
|
|
}
|
|
|
|
func (h branchesHalf) ByFingerprint(ctx context.Context, fingerprint string) (catalog.CatalogEntry, meshcatalogclient.EntryState) {
|
|
return h.b.Resolve(ctx, fingerprint)
|
|
}
|