C-R3: the runner's queue keeps the pipelines running
The seat mesh-pipeline-runner's state queue gains the key form running.<pipeline>, value
{pipeline}, written when a pipeline is placed and deleted at its end, its cancel or its approval
wait, so pipelines-at-once is judged against the running keys alone. A fixture row reads the new
form; the generator refused it before the form was defined.
Builds: design 47 H §748; lead answer H-A-96
Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -340,6 +340,41 @@ func DecodeQueueByWaitingSequenceValue(raw []byte) (QueueByWaitingSequenceValue,
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// QueueByRunningPipelineKey is the key of one value of the state queue under the form "running.<pipeline>".
|
||||
func QueueByRunningPipelineKey(pipeline string) string { return "running." + pipeline }
|
||||
|
||||
// ParseQueueByRunningPipelineKey reads the parts of a key of the form "running.<pipeline>", in the order of the form; the last result is false for a key of another form.
|
||||
func ParseQueueByRunningPipelineKey(key string) (string, bool) {
|
||||
rest := key
|
||||
if !strings.HasPrefix(rest, "running.") {
|
||||
return "", false
|
||||
}
|
||||
rest = rest[8:]
|
||||
if rest == "" {
|
||||
return "", false
|
||||
}
|
||||
v1 := rest
|
||||
rest = ""
|
||||
if rest != "" {
|
||||
return "", false
|
||||
}
|
||||
return v1, true
|
||||
}
|
||||
|
||||
// DecodeQueueByRunningPipelineValue reads one value of the state queue under the form "running.<pipeline>", refusing a field QueueByRunningPipelineValue does not know and any text after the value.
|
||||
func DecodeQueueByRunningPipelineValue(raw []byte) (QueueByRunningPipelineValue, error) {
|
||||
var v QueueByRunningPipelineValue
|
||||
dec := json.NewDecoder(bytes.NewReader(raw))
|
||||
dec.DisallowUnknownFields()
|
||||
if err := dec.Decode(&v); err != nil {
|
||||
return v, err
|
||||
}
|
||||
if dec.More() {
|
||||
return v, errors.New("text after the value")
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// KeptByLevelDigestKey is the key of one value of the state kept under the form "<level>.<digest>".
|
||||
func KeptByLevelDigestKey(level, digest string) string { return level + "." + digest }
|
||||
|
||||
@@ -1259,6 +1294,12 @@ type QueueByQueueNextValue = int64
|
||||
// QueueByWaitingSequenceValue is one value of the state queue under the key waiting.<sequence>.
|
||||
type QueueByWaitingSequenceValue = Waiting
|
||||
|
||||
// QueueByRunningPipelineValue is one value of the state queue under the key running.<pipeline>.
|
||||
type QueueByRunningPipelineValue struct {
|
||||
// the pipeline's key, as the key names it
|
||||
Pipeline string `json:"pipeline"`
|
||||
}
|
||||
|
||||
// KeptByLevelDigestValue is one value of the state kept under the key <level>.<digest>.
|
||||
type KeptByLevelDigestValue = KeptResult
|
||||
|
||||
|
||||
@@ -65,6 +65,12 @@ func TestFixtures(t *testing.T) {
|
||||
err := json.Unmarshal(b, &v)
|
||||
return v, err
|
||||
}, subjectIs: nil},
|
||||
{name: "a running pipeline in the queue", subject: "", given: "{\"pipeline\":\"main.3589\"}", wire: "{\"pipeline\":\"main.3589\"}",
|
||||
decode: func(b []byte) (any, error) {
|
||||
var v QueueByRunningPipelineValue
|
||||
err := json.Unmarshal(b, &v)
|
||||
return v, err
|
||||
}, subjectIs: nil},
|
||||
{name: "a pipeline waiting its turn, its seq given", subject: "", given: "{\"branch\":\"main\",\"call\":\"fedcba9876543210\",\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-0124\",\"module\":\"nats\",\"repository\":\"mesh-networking\",\"tier\":1}],\"outcome\":\"waiting\",\"pipeline\":\"main.3590\",\"revision\":13,\"seq\":2,\"source\":3590,\"steps\":[],\"v\":1}", wire: "{\"branch\":\"main\",\"call\":\"fedcba9876543210\",\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-0124\",\"module\":\"nats\",\"repository\":\"mesh-networking\",\"tier\":1}],\"outcome\":\"waiting\",\"pipeline\":\"main.3590\",\"revision\":13,\"seq\":2,\"source\":3590,\"steps\":[],\"v\":1}",
|
||||
decode: func(b []byte) (any, error) {
|
||||
var v PipelinesByBranchSourceValue
|
||||
|
||||
@@ -191,6 +191,13 @@
|
||||
"pipeline": "main.3590"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "a running pipeline in the queue",
|
||||
"of": "state:queue/running.<pipeline>",
|
||||
"given": {
|
||||
"pipeline": "main.3589"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "a pipeline waiting its turn, its seq given",
|
||||
"of": "state:pipelines/<branch>.<source>",
|
||||
|
||||
@@ -755,7 +755,7 @@
|
||||
"name": "queue",
|
||||
"template": "state",
|
||||
"history": 1,
|
||||
"description": "the pipelines waiting their turn under pipelines-at-once, the lowest sequence read first by key order (design 47 H §748, H-A-36, H-A-72)",
|
||||
"description": "the pipelines waiting their turn under pipelines-at-once, the lowest sequence read first by key order, and the pipelines running (design 47 H §748, H-A-36, H-A-72, H-A-96)",
|
||||
"key-forms": [
|
||||
{
|
||||
"key": "queue.next",
|
||||
@@ -771,6 +771,22 @@
|
||||
"$ref": "#/defs/Waiting"
|
||||
},
|
||||
"description": "a waiting pipeline, its sequence 20 digits"
|
||||
},
|
||||
{
|
||||
"key": "running.<pipeline>",
|
||||
"value": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"pipeline": {
|
||||
"type": "string",
|
||||
"description": "the pipeline's key, as the key names it"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"pipeline"
|
||||
]
|
||||
},
|
||||
"description": "a running pipeline, written by compare-and-set when it is placed and deleted at its end, its cancel or its approval wait; pipelines-at-once is judged against these keys alone (H-A-96)"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -123,6 +123,12 @@ export declare function queueByWaitingSequenceKey(sequence: string): string;
|
||||
/** The parts of a key of the form "waiting.<sequence>", or undefined for a key of another form. */
|
||||
export declare function parseQueueByWaitingSequenceKey(_key: string): { sequence: string } | undefined;
|
||||
|
||||
/** The key of one value of the state queue under the form "running.<pipeline>". */
|
||||
export declare function queueByRunningPipelineKey(pipeline: string): string;
|
||||
|
||||
/** The parts of a key of the form "running.<pipeline>", or undefined for a key of another form. */
|
||||
export declare function parseQueueByRunningPipelineKey(_key: string): { pipeline: string } | undefined;
|
||||
|
||||
/** The key of one value of the state kept under the form "<level>.<digest>". */
|
||||
export declare function keptByLevelDigestKey(level: string, digest: string): string;
|
||||
|
||||
@@ -769,6 +775,12 @@ export type QueueByQueueNextValue = number;
|
||||
/** is one value of the state queue under the key waiting.<sequence>. */
|
||||
export type QueueByWaitingSequenceValue = Waiting;
|
||||
|
||||
/** is one value of the state queue under the key running.<pipeline>. */
|
||||
export interface QueueByRunningPipelineValue {
|
||||
/** the pipeline's key, as the key names it */
|
||||
"pipeline": string;
|
||||
}
|
||||
|
||||
/** is one value of the state kept under the key <level>.<digest>. */
|
||||
export type KeptByLevelDigestValue = KeptResult;
|
||||
|
||||
|
||||
@@ -203,6 +203,23 @@ export function parseQueueByWaitingSequenceKey(_key) {
|
||||
return { sequence };
|
||||
}
|
||||
|
||||
/** The key of one value of the state queue under the form "running.<pipeline>". */
|
||||
export function queueByRunningPipelineKey(pipeline) {
|
||||
return "running." + pipeline;
|
||||
}
|
||||
|
||||
/** The parts of a key of the form "running.<pipeline>", or undefined for a key of another form. */
|
||||
export function parseQueueByRunningPipelineKey(_key) {
|
||||
let _rest = _key;
|
||||
if (!_rest.startsWith("running.")) return undefined;
|
||||
_rest = _rest.slice(8);
|
||||
if (_rest === "") return undefined;
|
||||
const pipeline = _rest;
|
||||
_rest = "";
|
||||
if (_rest !== "") return undefined;
|
||||
return { pipeline };
|
||||
}
|
||||
|
||||
/** The key of one value of the state kept under the form "<level>.<digest>". */
|
||||
export function keptByLevelDigestKey(level, digest) {
|
||||
return level + "." + digest;
|
||||
|
||||
Reference in New Issue
Block a user