Files
mesh-delivery/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline-tools/queue.go
T
jschoubben 213668df49 R14: the queue's tools, runner_waiting and runner_place over the verb place
The seat verb place places a waiting pipeline ahead of its turn, written in the hand-act log first:
its running key now, over the bound, its waiting key deleted, its steps placed as at its turn with
wait-ended; a pipeline not waiting is refused. The tool runner_place asks it with the pipeline and
why; runner_waiting lists the waiting pipelines, lowest sequence first, from the state queue. Both
are in the manifest's tools.

Builds: design 47 H §748; lead answer H-A-53

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-20 04:56:31 +01:00

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
}