B4 (H-A-454): publishes is the builder's own work-queue stream, read by the verb publish-queue

The work queue publishes is declared in the manifest's old streams section
(retention work-queue, duplicates 24 h, max-deliveries 10, 64 MiB, 7 days), the
module's own stream consumed on the module's account, so the bus binding asked
of the broker seat goes; the consumers per holder and class are still made at
run time. The seat mesh-builds gains the read verb publish-queue, served by the
builder from its own stream (counts per holder and class, oldest and newest, a
list capped at 50, capped past 4,000 items read), and builder_publish_queue asks
it in place of the runtime's stream and work-queue reads. Two whole tests of a
gone artifact are folded into one, so the builder's integration count stays at
18 with the publishes whole test.

Builds: design 47 H2 §793, §819, §820; H-A-440 (1), H-A-446 (2), H-A-454 and its addendum
This commit is contained in:
2026-11-22 02:35:32 +01:00
parent d6d15a5497
commit b6a7e0bad3
16 changed files with 520 additions and 135 deletions
@@ -435,7 +435,7 @@ func main() {
tools = append(tools, reservedTools(rr, buildAgain, time.Now, meshhandactsclient.Recorder{Ask: stdio.Ask})...)
as := stdio.State(versions.ActedState)
tools = append(tools, publishActTools(buildAgain, time.Now, meshhandactsclient.Recorder{Ask: stdio.Ask})...)
tools = append(tools, republishTools(workQueueReader(stdio.BusState, versions.PublishesLocal), readerOf(as), readerOf(reasks), buildAgain, time.Now, meshhandactsclient.Recorder{Ask: stdio.Ask})...)
tools = append(tools, republishTools(publishQueueVia(stdio.Ask), readerOf(as), readerOf(reasks), buildAgain, time.Now, meshhandactsclient.Recorder{Ask: stdio.Ask})...)
ws := stdio.State(build.WaitsState)
wr := versions.Reader{Keys: ws.Keys, Get: func(key string) (json.RawMessage, bool, error) {
e, err := ws.Get(key)
@@ -4,13 +4,12 @@ import (
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
"time"
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
stdio "git.novox.be/novox/mesh-sdk/go"
"git.novox.be/novox/mesh-sdk/go/buscalls"
"mesh-delivery-builder/internal/build"
"mesh-delivery-builder/internal/versions"
@@ -55,54 +54,23 @@ func onePage(page func(after string, maxBytes int, budget time.Duration) (stdio.
return out, nil
}
// workQueuePageItems and workQueueItemsRead bound the read of the work queue publishes: pages of 500 items, at most 4,000 read
// (H-A-293: past them the answer is capped, naming the items read and the queue's size).
const (
workQueuePageItems = 500
workQueueItemsRead = 4000
)
// publishQueueVerbKey is the seat verb builder_publish_queue asks (the manifest's invokes): the builder reads its own work queue
// publishes (design 47 H2 §793, H-A-454).
const publishQueueVerbKey = "seat:" + meshbuilds.Seat + "." + meshbuilds.VerbPublishQueue
// workQueueReader is the builder's work queue local as the versions package's reader (design 47 H2 §793, H-A-448): its items read
// through the tool runtime's stream read in pages, each keyed by its sequence, and its size through the work queue's size; a
// read past workQueueItemsRead is capped. call is stdio.BusState.
func workQueueReader(call func(method string, params any) (json.RawMessage, error), local string) versions.Reader {
none := func() ([]string, error) { return nil, errors.ErrUnsupported }
return versions.Reader{Keys: none, All: func() (versions.StatePage, error) {
out := versions.StatePage{Values: map[string]json.RawMessage{}}
from := uint64(0)
for {
raw, err := call(buscalls.StreamRead, buscalls.StreamReadRequest{Stream: local, From: from, Limit: workQueuePageItems})
if err != nil {
return out, err
}
var pg buscalls.StreamPage
if err := json.Unmarshal(raw, &pg); err != nil {
return out, fmt.Errorf("the work queue %s answered what is no page of items: %w", local, err)
}
for _, m := range pg.Messages {
out.Values[strconv.FormatUint(m.Sequence, 10)] = m.Body
}
if pg.Next == 0 || len(pg.Messages) == 0 {
return out, nil
}
if len(out.Values) >= workQueueItemsRead {
out.More = true
break
}
from = pg.Next
}
raw, err := call(buscalls.WorkQueueSize, buscalls.WorkQueueRequest{Queue: local})
var size buscalls.WorkQueueSized
if err == nil {
err = json.Unmarshal(raw, &size)
}
// publishQueueVia asks the seat mesh-builds' verb publish-queue through ask (stdio.Ask).
func publishQueueVia(ask func(key string, body any) (json.RawMessage, error)) func(module, version string) (meshbuilds.PublishQueueAnswer, error) {
return func(module, version string) (meshbuilds.PublishQueueAnswer, error) {
var a meshbuilds.PublishQueueAnswer
raw, err := ask(publishQueueVerbKey, meshbuilds.PublishQueueInput{Module: module, Version: version})
if err != nil {
out.InfoWords = fmt.Sprintf("the work queue's size cannot be read: %v", err)
} else {
out.Keys, out.Bytes = size.Count, size.Bytes
return a, fmt.Errorf("the builder's verb %s did not answer: %w", meshbuilds.VerbPublishQueue, err)
}
return out, nil
}}
if err := json.Unmarshal(raw, &a); err != nil {
return a, fmt.Errorf("the verb %s answered what is no queue: %w", meshbuilds.VerbPublishQueue, err)
}
return a, nil
}
}
// publishActTools are builder_publish_drop and builder_publish_first (design 47 H2 §793): hand acts, recorded in the hand-act log
@@ -147,7 +115,7 @@ func publishActTools(ask queueAsker, now func() time.Time, acts meshhandactsclie
// republishTools are builder_publish_again and builder_publish_queue (design 47 G §588). The publish again is a hand act:
// it is recorded in the hand-act log first, then written to reasks for the builder, which owns the queue, to answer
// with the versions it queued.
func republishTools(queue, acted, reasks versions.Reader, ask queueAsker, now func() time.Time, acts meshhandactsclient.Recorder) []stdio.Tool {
func republishTools(queue func(module, version string) (meshbuilds.PublishQueueAnswer, error), acted, reasks versions.Reader, ask queueAsker, now func() time.Time, acts meshhandactsclient.Recorder) []stdio.Tool {
str := func(args map[string]any, k string) string { s, _ := args[k].(string); return strings.TrimSpace(s) }
return []stdio.Tool{
{Name: versions.PublishAgainTool, Description: versions.PublishAgainDescription,
@@ -182,7 +150,11 @@ func republishTools(queue, acted, reasks versions.Reader, ask queueAsker, now fu
"module": map[string]any{"type": "string", "description": "list only this module's queued versions, each with its class"},
"version": map[string]any{"type": "string", "description": "with module: only this version, MAJOR.MINOR.PATCH"}}},
Run: func(args map[string]any) (any, error) {
return versions.AnswerQueue(queue, acted, reasks, str(args, "module"), str(args, "version"))
q, err := queue(str(args, "module"), str(args, "version"))
if err != nil {
return nil, err
}
return versions.AnswerQueue(q, acted, reasks)
}},
}
}
@@ -8,8 +8,8 @@ import (
"time"
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
stdio "git.novox.be/novox/mesh-sdk/go"
"git.novox.be/novox/mesh-sdk/go/buscalls"
"mesh-delivery-builder/internal/build"
@@ -65,33 +65,25 @@ func TestAStateIsReadInOnePage(t *testing.T) {
t.Errorf("health four minutes in = %+v, want healthy", a)
}
})
// Design 47 H2 §793, H-A-448: builder_publish_queue reads the work queue publishes through the runtime's stream read, in pages,
// and a read past its bound is capped with the queue's size from the work queue's size; builder_publish_drop and
// Design 47 H2 §793, H-A-454: builder_publish_queue asks the seat mesh-builds' verb publish-queue, which the builder serves from
// its own stream, and answers its counts, list and cap with the states beside them; builder_publish_drop and
// builder_publish_first record the hand act first, then write their reasks value.
t.Run("the work queue is read in pages, capped past its bound", func(t *testing.T) {
for _, total := range []int{1200, 9000} {
var methods []string
call := func(method string, params any) (json.RawMessage, error) {
methods = append(methods, method)
if method == buscalls.WorkQueueSize {
return json.Marshal(buscalls.WorkQueueSized{Fill: buscalls.Fill{Count: uint64(total), Bytes: 4096}})
}
req := params.(buscalls.StreamReadRequest)
var pg buscalls.StreamPage
for n := req.From + 1; n <= uint64(total) && len(pg.Messages) < req.Limit; n++ {
pg.Messages = append(pg.Messages, buscalls.StreamMessage{Sequence: n, Body: json.RawMessage(`{"holder":"oci","class":"again"}`)})
pg.Next = n
}
if pg.Next == uint64(total) {
pg.Next = 0
}
return json.Marshal(pg)
}
pg, err := workQueueReader(call, versions.PublishesLocal).All()
capped := total > workQueueItemsRead
if err != nil || pg.More != capped || len(pg.Values) != min(total, workQueueItemsRead) || (capped && pg.Keys != uint64(total)) {
t.Errorf("%d items: read %d, more %v, keys %d (%v) after %v", total, len(pg.Values), pg.More, pg.Keys, err, methods)
}
t.Run("the queue is the builder's verb publish-queue", func(t *testing.T) {
var asked []string
ask := func(key string, body any) (json.RawMessage, error) {
in := body.(meshbuilds.PublishQueueInput)
asked = append(asked, key+" "+in.Module)
return json.Marshal(meshbuilds.PublishQueueAnswer{Total: 9000, Listed: 1, Capped: true, ItemsRead: 4000, QueueItems: 9000, QueueBytes: 4096,
Counts: []meshbuilds.PublishQueueAnswerCountsItem{{Holder: "oci", Class: versions.PublishClassStart, Count: 4000}},
Queue: []meshbuilds.PublishQueueAnswerQueueItem{{Holder: "oci", Module: "m", Version: "0.1.0", Class: versions.PublishClassStart}}})
}
none := versions.Reader{Keys: func() ([]string, error) { return nil, nil }}
tools := republishTools(publishQueueVia(ask), none, none, nil, time.Now, meshhandactsclient.Recorder{})
raw, err := tools[1].Run(map[string]any{"module": "m"})
a, _ := raw.(versions.Queued)
if err != nil || fmt.Sprint(asked) != "[seat:mesh-builds.publish-queue m]" || a.Total != 9000 || len(a.Queue) != 1 || a.Queue[0].Module != "m" ||
len(a.Counts) != 1 || !a.Capped || len(a.Read) != 1 || a.Read[0].KeysRead != 4000 || a.Read[0].StateKeys != 9000 {
t.Errorf("%s asked %v, answered %+v (%v): want the verb asked with the module, its answer carried with its cap", tools[1].Name, asked, a, err)
}
})
t.Run("drop and first record the hand act, then ask the builder", func(t *testing.T) {
@@ -103,9 +103,16 @@ func revisionOf(t *testing.T, b *bed, module string) uint64 {
return e.Revision()
}
// TestAGoneArtifactIsBuiltAgain: 1937/AC3 and AC4, one whole test of the two (design 47 H2 §819: the builder's integration count does
// not rise with the work queue publishes' whole test).
func TestAGoneArtifactIsBuiltAgain(t *testing.T) {
t.Run("a done key whose blob is gone is built again at start", aDoneKeyWhoseBlobIsGoneIsBuiltAgainAtStart)
t.Run("artifacts-gone leads the builder to build the key again", artifactsGoneLeadsTheBuilderToBuildTheKeyAgain)
}
// 1937/AC3 (integration): the builder, started whole, finds the done key of the trunk's fingerprint naming a blob held
// answers gone, builds it again as a new revision whose step says so, and leaves the rebuilt key done.
func TestADoneKeyWhoseBlobIsGoneIsBuiltAgainAtStart(t *testing.T) {
func aDoneKeyWhoseBlobIsGoneIsBuiltAgainAtStart(t *testing.T) {
b := startBed(t)
eventsConsumer(t, b, "n1")
manifest := b.archive(t, "ca-trust", "modules/ca-trust", commit)
@@ -135,7 +142,7 @@ func TestADoneKeyWhoseBlobIsGoneIsBuiltAgainAtStart(t *testing.T) {
// 1937/AC4 (integration): a done key whose blob held answers held at start stays done; when the controller says
// artifacts-gone for it, the builder asks again and builds it again.
func TestArtifactsGoneLeadsTheBuilderToBuildTheKeyAgain(t *testing.T) {
func artifactsGoneLeadsTheBuilderToBuildTheKeyAgain(t *testing.T) {
b := startBed(t)
eventsConsumer(t, b, "n1")
manifest := b.archive(t, "ca-trust", "modules/ca-trust", commit)
@@ -8,7 +8,6 @@ import (
"context"
"errors"
"fmt"
"git.novox.be/novox/mesh-contracts/go/seats/meshbroker"
"io"
"io/fs"
"log"
@@ -40,7 +39,6 @@ import (
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
"git.novox.be/novox/mesh-sdk/go/buscompose"
"git.novox.be/novox/mesh-sdk/go/membership"
"git.novox.be/novox/mesh-sdk/go/operatorask"
"git.novox.be/novox/mesh-sdk/go/process"
"git.novox.be/novox/mesh-sdk/go/seatlist"
@@ -270,14 +268,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
// The versions' hand acts (builder_publish_again, builder_floor_again) come through reasks, as builder_build_again.
acts := versions.Acts{Numberer: numberer, DropReserved: reserved.dropped, Reconsider: b.Reconsider}
// A reserved version left unpublished is published again, by the builder on an event or by a person's tool (design 47 G
// §588): its items on the work queue publishes its requires asks for, named by the bus's binding (design 47 H2 §793, H-A-448).
// §588): its items on the work queue publishes, the module's own stream of its old streams section (design 47 H2 §793, H-A-454).
actedKV := process.AwaitBucket(ctx, js, conn, own.acted, "no version is published again on an event or by builder_publish_again", logger.Printf)
publishesBinding := process.NewBinding(meshbroker.Seat, cred.Module, calls.CallKept, logger.Printf, versions.PublishesLocal)
if err := publishesBinding.Register(hub); err != nil {
return fmt.Errorf("hearing the bus's binding of %s: %w", versions.PublishesLocal, err)
}
pq := &publishQueue{js: js, logf: logger.Printf,
binding: func() (membership.BusBinding, error) { return publishesBinding.Names(versions.PublishesLocal) }}
pq := &publishQueue{js: js, logf: logger.Printf, binding: publishesOf(cred.Module)}
republish := &versions.Republisher{Reserved: reserved.r, Put: pq.put,
Entry: entryVia(calls.Call), Send: sendVia(calls.CallKeptAsk),
Unreleased: reserved.unreleasedWords, Logf: logger.Printf,
@@ -355,10 +348,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
return fmt.Errorf("hearing the operator's answers: %w", err)
}
retake := &retaking{rt: &build.Retaker{Builder: b, Acted: retakeActed, Entry: entryVia(calls.Call), Ask: operator.Ask, Logf: logger.Printf}}
// Once the bus names the work queue: what waits on it is pulled, and the old state's items are put on it once (§793).
publishesBinding.Start()
// What waits on the work queue is pulled, and the old state's items are put on it once (§793).
go func() {
publishesBinding.Ask(versions.PublishesLocal)
if err := pq.learnAll(ctx); err != nil {
logger.Printf("the publishes waiting on the work queue %s are not pulled yet: %v; each holder's are pulled when an item of it is put", versions.PublishesLocal, err)
}
@@ -531,7 +522,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
// published (H-A-328): whether a package built at a fingerprint is published, asked by the runner writing a wait on it.
meshbuilds.VerbPublished: publishedVerb(ctx, reserved.r.PublishedOf),
// drop (§778; H-A-401, H-A-404): an ask its caller no longer waits for ends could-not-run naming the drop.
meshbuilds.VerbDrop: dropVerb(steps)})
meshbuilds.VerbDrop: dropVerb(steps),
// publish-queue (§793; H-A-454): the work queue publishes read from its own stream, for builder_publish_queue.
meshbuilds.VerbPublishQueue: publishQueueVerb(ctx, pq)})
if err != nil {
return fmt.Errorf("answering the verb reserved: %w", err)
}
@@ -14,8 +14,8 @@ import (
"github.com/nats-io/nats.go/jetstream"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-sdk/go/membership"
"mesh-delivery-builder/internal/versions"
)
@@ -23,12 +23,14 @@ import (
// Design 47 H2 §793 (whole, against the bus): the builder's work queue publishes, its pull consumers made as it learns a holder.
// A live publish enqueued behind 100 again items while the builder was away is sent first; a dropped item is never sent, and
// put again within the duplicates window is not stored; the move of the old state run twice puts each item once, and asks the
// bus module to drop the old state.
// bus module to drop the old state. The seat mesh-builds' verb publish-queue reads the stream: counts per holder and class, the
// oldest and newest, the live item listed first (H-A-454).
func TestThePublishQueueSendsLiveFirstAndNeverADroppedItem(t *testing.T) {
b := startBed(t)
ctx := b.ctx
bind := membership.BusBinding{Local: versions.PublishesLocal, Stream: "mesh-delivery-builder_publishes", Subject: "mesh.bus.mesh-delivery-builder.publishes"}
if _, err := b.js.CreateOrUpdateStream(ctx, jetstream.StreamConfig{Name: bind.Stream, Subjects: []string{bind.Subject + ".>"},
// The stream as the manifest's old streams section declares it: the module's own, retention work-queue, duplicates 24 hours.
bind, _ := publishesOf("mesh-delivery-builder")()
if _, err := b.js.CreateOrUpdateStream(ctx, jetstream.StreamConfig{Name: bind.Stream, Subjects: []string{bind.Subject + ".publish.>"},
Retention: jetstream.WorkQueuePolicy, Discard: jetstream.DiscardNew, Duplicates: 24 * time.Hour, MaxAge: 7 * 24 * time.Hour}); err != nil {
t.Fatal(err)
}
@@ -51,7 +53,7 @@ func TestThePublishQueueSendsLiveFirstAndNeverADroppedItem(t *testing.T) {
sentCh <- q.Module
return versions.SendFate{Sent: true}
}}
pq := &publishQueue{js: b.js, ackWait: time.Minute, logf: t.Logf, take: items.take, binding: func() (membership.BusBinding, error) { return bind, nil }}
pq := &publishQueue{js: b.js, ackWait: time.Minute, logf: t.Logf, take: items.take, binding: publishesOf("mesh-delivery-builder")}
item := func(module, class string) versions.QueuedPublish {
return versions.QueuedPublish{V: 1, Holder: "oci", Module: module, Version: "0.1.0", Artifacts: map[string]string{module + ":a": "sha256:a"}, Class: class, Queued: time.Now()}
}
@@ -74,6 +76,12 @@ func TestThePublishQueueSendsLiveFirstAndNeverADroppedItem(t *testing.T) {
if dup, err := pq.put(ctx, item("dropme", versions.PublishClassStart)); err != nil || !dup {
t.Errorf("a dropped item put again within the window: duplicate %v (%v), want it not stored", dup, err)
}
raw, err := publishQueueVerb(ctx, pq)("op@node", json.RawMessage(`{}`))
if a, ok := raw.(meshbuilds.PublishQueueAnswer); err != nil || !ok || a.Total != 101 || len(a.Counts) != 2 || a.Counts[0].Class != versions.PublishClassStart ||
a.Counts[0].Count != 100 || a.Counts[1].Count != 1 || a.Counts[0].Oldest.After(a.Counts[0].Newest) || len(a.Queue) != versions.PublishQueueListCap ||
a.Queue[0].Module != "live" || a.Capped {
t.Errorf("publish-queue answered %+v (%v), want 101 items, oci's 100 again and 1 live, fifty listed, the live first", raw, err)
}
if err := pq.learnAll(ctx); err != nil {
t.Fatal(err)
}
@@ -16,7 +16,10 @@ import (
"github.com/nats-io/nats.go"
"github.com/nats-io/nats.go/jetstream"
"git.novox.be/novox/mesh-sdk/go/membership"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
"git.novox.be/novox/mesh-sdk/go/buscompose"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-sdk/go/process"
"mesh-delivery-builder/internal/build"
"mesh-delivery-builder/internal/versions"
@@ -524,14 +527,15 @@ func builtOf(all []versions.ReservedVersion) []versions.ReservedVersion {
return out
}
// publishQueue is the builder's work queue publishes on the bus (design 47 H2 §793; H-A-440, H-A-446 (2), H-A-448): asked for in
// its requires and named by the bus's binding; each item on `<binding subject>.publish.<holder>.<class>.<module>.<version>` under
// the message id `<holder>.<class>.<module>.<version>`. The builder makes the pull consumers at run time as it learns a holder,
// publishQueue is the builder's work queue publishes on the bus (design 47 H2 §793; H-A-440, H-A-446 (2), H-A-454): a stream of
// the manifest's old streams section with the work-queue retention, the module's own, consumed by the process on the module's
// account; each item on `mesh.stream.<module>.event.publish.<holder>.<class>.<module>.<version>` under the message id
// `<holder>.<class>.<module>.<version>`. The builder makes the pull consumers at run time as it learns a holder,
// `publishes-<holder>-<class>`, with ack wait publish-pause-max, max ack pending four and max deliveries ten, and pulls the live
// class first, at most four sends at once per holder.
type publishQueue struct {
js jetstream.JetStream
binding func() (membership.BusBinding, error)
binding func() (publishesStream, error)
ackWait time.Duration
take func(ctx context.Context, m itemMsg)
logf func(string, ...any)
@@ -540,6 +544,16 @@ type publishQueue struct {
pulling map[string]bool
}
// publishesStream is where the work queue publishes is on the bus: its stream's name and the subject its items open with.
type publishesStream struct{ Stream, Subject string }
// publishesOf is module's work queue publishes, its own stream (H-A-454): the stream's bus name and its events' subject.
func publishesOf(module string) func() (publishesStream, error) {
b := publishesStream{Stream: catalogue.StreamBusName(versions.PublishesLocal),
Subject: strings.TrimSuffix(buscompose.ModuleStreamSubject(module, ""), ".")}
return func() (publishesStream, error) { return b, nil }
}
// The consumers' numbers (H-A-446 (2)): at most four sends in flight per holder and class, and ten deliveries, the work queue's
// largest; the builder ends an item at publish-tries anyway.
const (
@@ -553,7 +567,7 @@ func publishesConsumer(holder, class string) string {
}
// subject is the item's subject on the bus.
func (pq *publishQueue) subject(b membership.BusBinding, q versions.QueuedPublish) string {
func (pq *publishQueue) subject(b publishesStream, q versions.QueuedPublish) string {
return b.Subject + "." + versions.PublishEvent(q.Holder, q.Class, q.Module, q.Version)
}
@@ -744,6 +758,53 @@ func (pq *publishQueue) itemsOf(ctx context.Context, module, version, class stri
return out, st, nil
}
// publishQueueItemsRead bounds the verb publish-queue's read of the work queue: at most 4,000 items, past them the answer is capped,
// naming the items read and the queue's size (H-A-293).
const publishQueueItemsRead = 4000
// reader is the work queue as the versions package's reader, for the seat mesh-builds' verb publish-queue (§793, H-A-454): its
// items read from the stream by sequence, at most publishQueueItemsRead, each keyed by its sequence; a queue holding more is read
// capped, with the stream's message count and bytes.
func (pq *publishQueue) reader(ctx context.Context) versions.Reader {
none := func() ([]string, error) { return nil, errors.ErrUnsupported }
return versions.Reader{Keys: none, All: func() (versions.StatePage, error) {
out := versions.StatePage{Values: map[string]json.RawMessage{}}
b, err := pq.binding()
if err != nil {
return out, err
}
st, err := pq.js.Stream(ctx, b.Stream)
if err != nil {
return out, err
}
info, err := st.Info(ctx)
if err != nil {
return out, err
}
held := int(info.State.Msgs)
if held == 0 {
return out, nil
}
// A work queue takes no second consumer over its subjects, so its items are read by sequence, the deleted passed over.
for seq := info.State.FirstSeq; seq <= info.State.LastSeq && len(out.Values) < publishQueueItemsRead; seq++ {
m, err := st.GetMsg(ctx, seq)
if errors.Is(err, jetstream.ErrMsgNotFound) {
continue // acknowledged or terminated since
}
if err != nil {
return out, err
}
if strings.HasPrefix(m.Subject, b.Subject+".publish.") {
out.Values[strconv.FormatUint(seq, 10)] = json.RawMessage(m.Data)
}
}
if held > len(out.Values) && len(out.Values) >= publishQueueItemsRead {
out.More, out.Keys, out.Bytes = true, info.State.Msgs, info.State.Bytes
}
return out, nil
}}
}
// drop is builder_publish_drop (§793): the version's publish item is ended with who dropped it and why, so no item of it is ever
// sent or put again; its items waiting on the work queue are removed, and one held is terminated.
func (pq *publishQueue) drop(ctx context.Context, items *publishItems, module, version, by, why string) (string, error) {
@@ -886,3 +947,17 @@ func moveOld(ctx context.Context, js jetstream.JetStream, bucket, module string,
// natsDropTool is the bus module's drop of an entry no accepted manifest asks for (H-A-126), which the old state goes by.
const natsDropTool = "nats.nats_drop"
// publishQueueVerb is the handler of the seat mesh-builds' verb publish-queue (§793; H-A-454): the builder reads its own work queue
// and answers its counts per holder and class, the oldest and newest, and a capped list; builder_publish_queue asks it.
func publishQueueVerb(ctx context.Context, pq *publishQueue) process.SeatHandler {
return func(_ string, body json.RawMessage) (any, error) {
var in meshbuilds.PublishQueueInput
if len(body) > 0 {
if err := json.Unmarshal(body, &in); err != nil {
return nil, fmt.Errorf("the arguments do not fit the verb publish-queue: %w", err)
}
}
return versions.PublishQueueOf(pq.reader(ctx), in.Module, in.Version)
}
}