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
161 lines
7.7 KiB
Go
161 lines
7.7 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"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"
|
|
|
|
"mesh-delivery-builder/internal/build"
|
|
"mesh-delivery-builder/internal/versions"
|
|
)
|
|
|
|
// readerOf is a kept state as the versions package's reader: its values read in one page, one request for many (design 47 H
|
|
// H-A-290 (5), H-A-292), where a key-by-key read of a queue of two thousand keys outlasts the tool's call.
|
|
func readerOf(s stdio.KeptState) versions.Reader {
|
|
return versions.Reader{Keys: s.Keys, Get: func(key string) (json.RawMessage, bool, error) {
|
|
e, err := s.Get(key)
|
|
if err != nil || e == nil {
|
|
return nil, false, err
|
|
}
|
|
return e.Value, true, nil
|
|
}, All: func() (versions.StatePage, error) { return onePage(s.Page, s.Info) }}
|
|
}
|
|
|
|
// statePageBytes and statePageBudget bound the one page of a state read, so its answer fits one bus message and its time.
|
|
const (
|
|
statePageBytes = 768 * 1024
|
|
statePageBudget = 10 * time.Second
|
|
)
|
|
|
|
// onePage is the first page of a state's values, and never a second (H-A-292, H-A-293): when the state holds more, the page says
|
|
// so with the state's size from its info. A runtime that answers no page says errors.ErrUnsupported.
|
|
func onePage(page func(after string, maxBytes int, budget time.Duration) (stdio.StatePage, error), info func() (*stdio.StateInfo, error)) (versions.StatePage, error) {
|
|
pg, err := page("", statePageBytes, statePageBudget)
|
|
if err != nil {
|
|
return versions.StatePage{}, err
|
|
}
|
|
out := versions.StatePage{Values: make(map[string]json.RawMessage, len(pg.Entries)), More: pg.Next != ""}
|
|
for _, e := range pg.Entries {
|
|
out.Values[e.Key] = e.Value
|
|
}
|
|
if out.More {
|
|
if in, err := info(); err != nil || in == nil {
|
|
out.InfoWords = fmt.Sprintf("the state's info cannot be read: %v", err)
|
|
} else {
|
|
out.Keys, out.Bytes = in.Keys, in.Bytes
|
|
}
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// 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
|
|
|
|
// 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 {
|
|
return a, fmt.Errorf("the builder's verb %s did not answer: %w", meshbuilds.VerbPublishQueue, err)
|
|
}
|
|
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
|
|
// first, then written to reasks for the builder, which owns the work queue, to perform and answer.
|
|
func publishActTools(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) }
|
|
tool := func(name, mode, desc, what string) stdio.Tool {
|
|
return stdio.Tool{Name: name, Description: desc,
|
|
Input: map[string]any{"type": "object", "required": []string{"module", "version", "why"}, "properties": map[string]any{
|
|
"module": map[string]any{"type": "string", "description": "the item's module"},
|
|
"version": map[string]any{"type": "string", "description": "the item's version, MAJOR.MINOR.PATCH"},
|
|
"why": map[string]any{"type": "string", "description": "why, in plain words"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
key, value, err := build.NewPublishAct(mode, str(args, "module"), str(args, "version"), str(args, "why"), stdio.CallerOf(args), now())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if _, err := acts.Record(meshhandactsclient.Request{What: fmt.Sprintf("%s %s %s by hand", what, str(args, "module"), str(args, "version")),
|
|
Why: str(args, "why"), Cause: name, Verb: mode}); err != nil {
|
|
return nil, fmt.Errorf("the hand act was not recorded through mesh-hand-acts, so nothing was done: %w", err)
|
|
}
|
|
raw, err := ask(key, value)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
a, err := build.DecodeReAsk(raw)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if a.Refused {
|
|
return nil, errors.New(a.Answer)
|
|
}
|
|
return map[string]any{"key": key, "answer": a.Answer}, nil
|
|
}}
|
|
}
|
|
return []stdio.Tool{
|
|
tool(versions.PublishDropTool, build.ModePublishDrop, versions.PublishDropDescription, "dropped the publish of"),
|
|
tool(versions.PublishFirstTool, build.ModePublishFirst, versions.PublishFirstDescription, "put first the publish of"),
|
|
}
|
|
}
|
|
|
|
// 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 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,
|
|
Input: map[string]any{"type": "object", "required": []string{"why"}, "properties": map[string]any{
|
|
"module": map[string]any{"type": "string", "description": "only this module's reserved versions"},
|
|
"version": map[string]any{"type": "string", "description": "with module: only this reserved version, MAJOR.MINOR.PATCH"},
|
|
"why": map[string]any{"type": "string", "description": "why, in plain words"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
key, value, err := build.NewRepublish(str(args, "module"), str(args, "version"), str(args, "why"), stdio.CallerOf(args), now())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if _, err := acts.Record(meshhandactsclient.Request{What: fmt.Sprintf("published reserved versions again by hand (module %q, version %q)", str(args, "module"), str(args, "version")),
|
|
Why: str(args, "why"), Cause: versions.PublishAgainTool, Verb: "publish-again"}); err != nil {
|
|
return nil, fmt.Errorf("the hand act was not recorded through mesh-hand-acts, so nothing was queued: %w", err)
|
|
}
|
|
raw, err := ask(key, value)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
a, err := build.DecodeReAsk(raw)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if a.Refused {
|
|
return nil, errors.New(a.Answer)
|
|
}
|
|
return map[string]any{"key": key, "queued": a.Queued, "answer": a.Answer}, nil
|
|
}},
|
|
{Name: versions.PublishQueueTool, Description: versions.PublishQueueDescription,
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{
|
|
"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) {
|
|
q, err := queue(str(args, "module"), str(args, "version"))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return versions.AnswerQueue(q, acted, reasks)
|
|
}},
|
|
}
|
|
}
|