The seat generator gives every value, event and answer the wire field form (left out while 1) and a tolerant decoder answering the form it read; each contract carries its forms and a digest of its fields, and the compare fails a definition whose fields changed while its form did not. Every delivery seat is regenerated, and the readers take the form. Builds: design 47 H2 §780; H-A-352
54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
"strconv"
|
|
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
|
|
"mesh-delivery-pipeline/internal/pipeline"
|
|
)
|
|
|
|
// Waiting is one pipeline waiting its turn under pipelines-at-once, as runner_waiting lists it.
|
|
type Waiting struct {
|
|
Sequence int64 `json:"sequence"`
|
|
Pipeline string `json:"pipeline"`
|
|
}
|
|
|
|
// WaitingTool is runner_waiting: the waiting pipelines in their order, lowest sequence first, read from the runner's state
|
|
// queue (design 47 H §748).
|
|
func WaitingTool(queue pipeline.Kept) stdio.Tool {
|
|
return stdio.Tool{Name: Prefix + "_waiting",
|
|
Description: "The pipelines waiting their turn under pipelines-at-once, in their order (lowest sequence first), each with its sequence and pipeline key, read from the runner's state queue. runner_place places one ahead of its turn.",
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{}},
|
|
Run: func(map[string]any) (any, error) { return waitingOf(queue) }}
|
|
}
|
|
|
|
func waitingOf(queue pipeline.Kept) ([]Waiting, error) {
|
|
keys, err := queue.Keys()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("the state queue is not read: %w", err)
|
|
}
|
|
slices.Sort(keys)
|
|
out := []Waiting{}
|
|
for _, k := range keys {
|
|
seq, ok := seat.ParseQueueByWaitingSequenceKey(k)
|
|
if !ok {
|
|
continue
|
|
}
|
|
raw, err := queue.Value(k)
|
|
if err != nil || raw == nil {
|
|
continue
|
|
}
|
|
w, _, err := seat.DecodeQueueByWaitingSequenceValue(raw)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("the queue's %s is no waiting pipeline: %w", k, err)
|
|
}
|
|
n, _ := strconv.ParseInt(seq, 10, 64)
|
|
out = append(out, Waiting{Sequence: n, Pipeline: w.Pipeline})
|
|
}
|
|
return out, nil
|
|
}
|