An ask put while the builder is down waited for nobody: the plain subscription heard only what came while it ran. The builder now pulls every waiting ask from the seat's one worker, takes it once by its id in its state taken (for ask-taken-bound), says ask-taken at the pull, sends in-progress while it builds and acknowledges once the step's end is said. Its publish to a registry seat is a kept call carrying the publish's ask id. The manifest declares taken and the kept-call pace and ask-taken-bound as runtime settings. Builds: design 47 H2 §775, §777, §820; H-A-381
67 lines
2.4 KiB
Go
67 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"sync"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
)
|
|
|
|
// **The runner's build step ask is the builder's one entry point for a candidate** (design 47 G A-97, A-84, A-99): the seat
|
|
// mesh-builds' accepted kind `step`, heard on its subject, names the entry of one module by fingerprint; the builder reads it through
|
|
// the seat mesh-catalog's `entry`, builds it (build.Builder.BuildStep) and says the end as the seat's event step-ended.<node>, the
|
|
// ask's id as the event's id, which the runner holds the end to.
|
|
|
|
// entryWaits answers an entry by fingerprint from the catalog half or the seat's `entry`, waiting for the answer the entries
|
|
// keeper is told of (meshcatalogclient.Entries.Changed), never a timer.
|
|
type entryWaits struct {
|
|
branches *meshcatalogclient.Branches
|
|
manifest *entryManifests
|
|
mu sync.Mutex
|
|
waiting map[string][]chan meshcatalogclient.EntryRow
|
|
}
|
|
|
|
func newEntryWaits(branches *meshcatalogclient.Branches, manifests *entryManifests) *entryWaits {
|
|
w := &entryWaits{branches: branches, manifest: manifests, waiting: map[string][]chan meshcatalogclient.EntryRow{}}
|
|
prior := branches.Entries.Changed
|
|
branches.Entries.Changed = func(row meshcatalogclient.EntryRow) {
|
|
w.mu.Lock()
|
|
chans := w.waiting[row.Fingerprint]
|
|
delete(w.waiting, row.Fingerprint)
|
|
w.mu.Unlock()
|
|
for _, ch := range chans {
|
|
ch <- row
|
|
}
|
|
if prior != nil {
|
|
prior(row)
|
|
}
|
|
}
|
|
return w
|
|
}
|
|
|
|
// entry is build.Builder.StepEntry.
|
|
func (w *entryWaits) entry(ctx context.Context, fingerprint string) (meshcatalog.CatalogEntry, error) {
|
|
ch := make(chan meshcatalogclient.EntryRow, 1)
|
|
w.mu.Lock()
|
|
w.waiting[fingerprint] = append(w.waiting[fingerprint], ch)
|
|
w.mu.Unlock()
|
|
e, state := w.branches.Resolve(ctx, fingerprint)
|
|
if state == meshcatalogclient.EntryAsked {
|
|
select {
|
|
case row := <-ch:
|
|
if row.Entry == nil {
|
|
return meshcatalog.CatalogEntry{}, fmt.Errorf("the seat mesh-catalog holds no entry of it (%s)", row.State)
|
|
}
|
|
e, state = *row.Entry, row.State
|
|
case <-ctx.Done():
|
|
return meshcatalog.CatalogEntry{}, ctx.Err()
|
|
}
|
|
}
|
|
if state != meshcatalogclient.EntryAnswered {
|
|
return meshcatalog.CatalogEntry{}, fmt.Errorf("the seat mesh-catalog's entry of it is %s", state)
|
|
}
|
|
return e, w.manifest.keep(e) // the manifest the build is planned from
|
|
}
|