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:
@@ -12,6 +12,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -509,17 +510,20 @@ func PublishItemKey(module, version string) string {
|
||||
return PublishItemKeyPrefix + EscapeToken(module) + "." + EscapeToken(version)
|
||||
}
|
||||
|
||||
// AnswerQueue is builder_publish_queue over the work queue publishes (its items, read in pages through the tool runtime, §793,
|
||||
// H-A-448) and the two states as the tools bundle reads them (H-A-290 (5)): each read in bulk (Reader.All), the answer counted and capped at PublishQueueListCap whatever the queue holds; module (and version) narrow the
|
||||
// listed queue to one module's (one version's), so an item's class can be read.
|
||||
func AnswerQueue(queue, acted, reasks Reader, module, version string) (Queued, error) {
|
||||
out := Queued{Counts: []QueueCount{}, Queue: []QueuedPublish{}, Acted: map[string]uint64{}, Items: []PublishItem{}}
|
||||
// PublishQueueOf is the seat mesh-builds' verb publish-queue (design 47 H2 §793; H-A-454): the builder's read of its own work queue
|
||||
// publishes (queue, its items read in bulk, capped past its bound), small at any size of the queue (H-A-290 (5)): the items' count
|
||||
// per holder and class with the oldest and newest queue time, and the first PublishQueueListCap in the order they are sent; module
|
||||
// (and version) narrow the list to one module's (one version's), so an item's class can be read.
|
||||
func PublishQueueOf(queue Reader, module, version string) (meshbuilds.PublishQueueAnswer, error) {
|
||||
out := meshbuilds.PublishQueueAnswer{Counts: []meshbuilds.PublishQueueAnswerCountsItem{}, Queue: []meshbuilds.PublishQueueAnswerQueueItem{}}
|
||||
vals, c, err := queue.values(PublishesLocal)
|
||||
out.capped(c)
|
||||
if c != nil {
|
||||
out.Capped, out.ItemsRead, out.QueueItems, out.QueueBytes = true, int64(c.KeysRead), int64(c.StateKeys), int64(c.StateBytes)
|
||||
}
|
||||
if err != nil {
|
||||
return out, fmt.Errorf("the work queue %s cannot be read: %w", PublishesLocal, err)
|
||||
}
|
||||
counts := map[[2]string]*QueueCount{}
|
||||
counts := map[[2]string]*meshbuilds.PublishQueueAnswerCountsItem{}
|
||||
var listed []QueuedPublish
|
||||
for _, raw := range vals {
|
||||
var q QueuedPublish
|
||||
@@ -532,7 +536,7 @@ func AnswerQueue(queue, acted, reasks Reader, module, version string) (Queued, e
|
||||
out.Total++
|
||||
c := counts[[2]string{q.Holder, q.Class}]
|
||||
if c == nil {
|
||||
c = &QueueCount{Holder: q.Holder, Class: q.Class, Oldest: q.Queued, Newest: q.Queued}
|
||||
c = &meshbuilds.PublishQueueAnswerCountsItem{Holder: q.Holder, Class: q.Class, Oldest: q.Queued, Newest: q.Queued}
|
||||
counts[[2]string{q.Holder, q.Class}] = c
|
||||
}
|
||||
c.Count++
|
||||
@@ -571,10 +575,27 @@ func AnswerQueue(queue, acted, reasks Reader, module, version string) (Queued, e
|
||||
if len(out.Queue) == PublishQueueListCap {
|
||||
break
|
||||
}
|
||||
out.Queue = append(out.Queue, q)
|
||||
out.Queue = append(out.Queue, meshbuilds.PublishQueueAnswerQueueItem{Holder: q.Holder, Module: q.Module, Version: q.Version,
|
||||
Class: q.Class, Artifacts: q.Artifacts, Queued: q.Queued})
|
||||
}
|
||||
}
|
||||
out.Listed = len(out.Queue)
|
||||
out.Listed = int64(len(out.Queue))
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// AnswerQueue is builder_publish_queue: the seat mesh-builds' publish-queue answer the builder gave (q, §793, H-A-454) and the two
|
||||
// states as the tools bundle reads them (H-A-290 (5)), each read in bulk (Reader.All), capped at PublishQueueListCap.
|
||||
func AnswerQueue(q meshbuilds.PublishQueueAnswer, acted, reasks Reader) (Queued, error) {
|
||||
out := Queued{Total: int(q.Total), Counts: []QueueCount{}, Queue: []QueuedPublish{}, Listed: int(q.Listed), Acted: map[string]uint64{}, Items: []PublishItem{}}
|
||||
if q.Capped {
|
||||
out.capped(&StateCapped{State: PublishesLocal, KeysRead: int(q.ItemsRead), StateKeys: uint64(q.QueueItems), StateBytes: uint64(q.QueueBytes)})
|
||||
}
|
||||
for _, c := range q.Counts {
|
||||
out.Counts = append(out.Counts, QueueCount{Holder: c.Holder, Class: c.Class, Count: int(c.Count), Oldest: c.Oldest, Newest: c.Newest})
|
||||
}
|
||||
for _, it := range q.Queue {
|
||||
out.Queue = append(out.Queue, QueuedPublish{V: 1, Holder: it.Holder, Module: it.Module, Version: it.Version, Artifacts: it.Artifacts, Queued: it.Queued, Class: it.Class})
|
||||
}
|
||||
avals, c, err := acted.values(ActedState)
|
||||
out.capped(c)
|
||||
if err != nil {
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -239,7 +240,7 @@ func TestRepublish(t *testing.T) {
|
||||
return json.RawMessage(`{"mode":"publish","module":"m","version":"0.1.0","tries":3,"next-try":"2026-11-17T01:00:00Z","why":"w"}`), true, nil
|
||||
}}
|
||||
none := Reader{Keys: func() ([]string, error) { return nil, nil }}
|
||||
answer, err := AnswerQueue(none, none, items, "", "")
|
||||
answer, err := answerOf(none, none, items, "", "")
|
||||
if err != nil || len(answer.Items) != 1 || answer.Items[0].Tries != 3 || answer.Items[0].Version != "0.1.0" {
|
||||
t.Errorf("builder_publish_queue items = %+v (%v), want the one publish item with its tries", answer.Items, err)
|
||||
}
|
||||
@@ -384,6 +385,24 @@ func TestAQueuedItemIsSentWhileItsBuildStands(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// answerOf is builder_publish_queue whole: the builder's verb publish-queue over its work queue (queue), then the tool over the
|
||||
// verb's answer and the two states (design 47 H2 §793, H-A-454).
|
||||
func answerOf(queue, acted, reasks Reader, module, version string) (Queued, error) {
|
||||
q, err := PublishQueueOf(queue, module, version)
|
||||
if err != nil {
|
||||
return Queued{}, err
|
||||
}
|
||||
raw, err := json.Marshal(q) // the verb's answer travels the bus
|
||||
if err != nil {
|
||||
return Queued{}, err
|
||||
}
|
||||
var heard meshbuilds.PublishQueueAnswer
|
||||
if err := json.Unmarshal(raw, &heard); err != nil {
|
||||
return Queued{}, err
|
||||
}
|
||||
return AnswerQueue(heard, acted, reasks)
|
||||
}
|
||||
|
||||
// TestThePublishQueueToolAnswersAtAnySize: design 47 H H-A-290 (5) — builder_publish_queue over two thousand queued versions answers
|
||||
// within a second and small: counts per holder and class with the oldest and newest queue time, a list capped at fifty in the
|
||||
// order they are sent, and one module's item with its class; each state read in bulk where the reader can.
|
||||
@@ -407,7 +426,7 @@ func TestThePublishQueueToolAnswersAtAnySize(t *testing.T) {
|
||||
Get: func(k string) (json.RawMessage, bool, error) { gets++; v, ok := vals[k]; return v, ok, nil }}
|
||||
none := Reader{Keys: func() ([]string, error) { return nil, nil }}
|
||||
start := time.Now()
|
||||
a, err := AnswerQueue(queue, none, none, "", "")
|
||||
a, err := answerOf(queue, none, none, "", "")
|
||||
took := time.Since(start)
|
||||
raw, _ := json.Marshal(a)
|
||||
if err != nil || took > time.Second || a.Total != 2000 || len(a.Queue) != PublishQueueListCap || a.Listed != PublishQueueListCap || len(raw) > 64<<10 || gets != 0 {
|
||||
@@ -419,7 +438,7 @@ func TestThePublishQueueToolAnswersAtAnySize(t *testing.T) {
|
||||
if a.Queue[0].Class != PublishClassLive || a.Queue[0].Holder != "go" {
|
||||
t.Errorf("the list opens with %+v, want the go holder's live class, sent first", a.Queue[0])
|
||||
}
|
||||
one, err := AnswerQueue(queue, none, none, "m1995", "")
|
||||
one, err := answerOf(queue, none, none, "m1995", "")
|
||||
if err != nil || len(one.Queue) != 1 || one.Queue[0].Class != PublishClassLive || one.Total != 2000 {
|
||||
t.Errorf("one module's answer %+v (%v), want its item with its class", one.Queue, err)
|
||||
}
|
||||
@@ -427,12 +446,12 @@ func TestThePublishQueueToolAnswersAtAnySize(t *testing.T) {
|
||||
t.Errorf("a state one page holds is answered capped: %+v", a.Read)
|
||||
}
|
||||
queue.All = func() (StatePage, error) { return StatePage{Values: vals, More: true, Keys: 5000, Bytes: 3 << 20}, nil }
|
||||
if c, err := AnswerQueue(queue, none, none, "", ""); err != nil || !c.Capped || len(c.Read) != 1 || c.Read[0].State != PublishesLocal ||
|
||||
if c, err := answerOf(queue, none, none, "", ""); err != nil || !c.Capped || len(c.Read) != 1 || c.Read[0].State != PublishesLocal ||
|
||||
c.Read[0].KeysRead != 2000 || c.Read[0].StateKeys != 5000 || c.Read[0].StateBytes != 3<<20 || c.Total != 2000 {
|
||||
t.Errorf("a state past its one page answered capped %v, read %+v (%v): want capped, 2000 keys read of 5000, its size said (H-A-293)", c.Capped, c.Read, err)
|
||||
}
|
||||
queue.All = func() (StatePage, error) { return StatePage{}, errors.ErrUnsupported }
|
||||
if b, err := AnswerQueue(queue, none, none, "", ""); err != nil || b.Total != 2000 || gets != 2000 {
|
||||
if b, err := answerOf(queue, none, none, "", ""); err != nil || b.Total != 2000 || gets != 2000 {
|
||||
t.Errorf("a reader with no bulk read answered %d (%v) with %d single reads, want every key read one by one", b.Total, err, gets)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user