Files
mesh-delivery/modules/mesh-delivery-sdk/steprun/askers.go
T
jschoubben 9ab1c3b8f3 H-A-375: a declined pipeline step is put again on a node that has its need
A holder whose node lacks what a step's packages need (the artifact's
check-needs, now named on the integration step's ask) says the step's end
declined with needs and lacks, in place of could not run. The runner puts
it again under a new ask id naming in not-on the nodes that declined it;
a holder on a listed node hands it back at once. The nodes that can take it
are the holders of the step's seat and of the need's seat less those that
declined; when none is left the step ends could not run naming the need
and the nodes asked. The build-step part's form is 3, the runner seat's 5.

Builds: design 47 H2 H-A-375, H-A-445 (ADR 0552 §2, §4)
2026-11-22 02:08:40 +01:00

116 lines
4.9 KiB
Go

package steprun
import (
"encoding/json"
"fmt"
buildrun "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildrun"
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
)
// **A holder takes every asker's kind** (design 47 H §752, H-A-41: every account may call every verb; the asker judgement
// goes). An ask rides `mesh.seat.<seat>.accept.<queue>.<asker>`, the asker the asking seat's own name, and its kind stays in
// its body; the holder keys the step under that asker (design 47 G §481). On main's subject, which names no asker, it takes
// only a build and a run (design 47 G §543, A-184).
// KindOf is the word the seat definition gives an ask's kind: run for a run or a compose, else the ask's own kind.
func KindOf(ask sdkstep.StepAsk) string {
if ask.Run != nil || ask.Compose != nil {
return "run"
}
return ask.Kind
}
// askerRefusal is why an ask must not be taken from its subject: "" when it may be. Any named asker may ask any kind.
func (p *Puller) askerRefusal(msg *Pulled, ask sdkstep.StepAsk) (why string) {
if msg.Subject == "" {
return "" // a source that gives no subject (a test's)
}
_, _, asker, err := sdkstep.ParseAskSubjectBy(msg.Subject)
if err != nil {
return fmt.Sprintf("the ask came on %s, which is no accept subject of this seat", msg.Subject)
}
kind := KindOf(ask)
if asker == "" {
// Main's subject takes a build, a run and, until it goes, the checker's check and recheck (design 47 G A-184, §543).
if (ask.Build != nil && ask.Kind == sdkstep.AskDelivery) || kind == "run" || kind == sdkstep.AskCheck || kind == sdkstep.AskRecheck {
return ""
}
return fmt.Sprintf("the kind %s is not taken on main's subject, which takes only a build, a run and the checker's check and recheck (asker: none named)", kind)
}
return ""
}
// refuseAsker ends an ask whose asker may not ask its kind: its step key says failed with the reason, naming the kind and the
// asker, step-ended says failed, and the message is dropped.
func (p *Puller) refuseAsker(msg *Pulled, ask sdkstep.StepAsk, why string) {
key, err := sdkstep.AskStepKey(keyAsker(msg), p.Node, ask.ID)
if err == nil {
at := now().UTC()
step := sdkstep.Step{ID: ask.ID, Tool: ask.Kind + " ask", Node: p.Node, State: sdkstep.StepFailed, Started: at, Ended: at,
Reason: "error: " + why, Owner: buildrun.Owner, Run: int(msg.Delivered)}
err = writeEnd(p.Put, key, step)
}
if err != nil {
p.logf("the ask %s of the wrong asker cannot be answered on %s, so it is given back: %v", ask.ID, p.Node, err)
_ = msg.Nak()
return
}
p.logf("the ask %s is refused on %s: %s", ask.ID, p.Node, why)
p.sayAskEnded(msg, ask, sdkstep.OutcomeFailed, why)
_ = msg.Ack() // A-489: ended and written, so it leaves the work queue
}
// sayAskEnded says the end of an ask this holder ends without running it: its step-ended, an ask outside a pipeline as
// sayEnded says it, a pipeline step as its own form (design 47 G §602), so the runner that asked hears it.
func (p *Puller) sayAskEnded(msg *Pulled, ask sdkstep.StepAsk, outcome, said string) {
if ask.Step == nil {
p.sayEnded(msg, ask, outcome, said, nil, "")
} else if end, err := sdkstep.EndOf(ask, p.Node, outcome); err == nil {
// A pipeline step's end names its pipeline, step, commit and fingerprint (its own form, §602).
end.Said, end.At, end.Asker = said, now().UTC(), askerOf(msg, ask)
if body, err := sdkstep.EncodeStepEnded(end); err == nil {
p.say("step-ended", json.RawMessage(body), "step-ended."+ask.ID)
}
}
}
// sayDeclined says the end of an ask this node declined: a pipeline step's as the outcome declined with what it needs and
// what this node lacks, for the runner to put it again on a node that has it (design 47 H2 H-A-375, H-A-445); any other
// ask's as could not run, for its asker to put again (issue 890).
func (p *Puller) sayDeclined(msg *Pulled, ask sdkstep.StepAsk, needs, lacks []string, said string) {
if ask.Step == nil {
p.sayAskEnded(msg, ask, sdkstep.OutcomeCouldNotRun, said)
return
}
end, err := sdkstep.EndOf(ask, p.Node, sdkstep.OutcomeDeclined)
if err != nil {
return
}
end.Said, end.At, end.Asker, end.Needs, end.Lacks = said, now().UTC(), askerOf(msg, ask), needs, lacks
if body, err := sdkstep.EncodeStepEnded(end); err == nil {
p.say("step-ended", json.RawMessage(body), "step-ended."+ask.ID)
} else {
p.logf("the decline of the ask %s on %s is not said: %v", ask.ID, p.Node, err)
}
}
// PriorRuns is Puller.Prior over a steps state's read (a module's ReadSteps.Get): the Run of the step a key holds. Nil for no
// read (a test's), so the bus's delivery count stands.
func PriorRuns(get func(key string) (json.RawMessage, error)) func(string) int {
if get == nil {
return nil
}
return func(key string) int {
raw, err := get(key)
if err != nil || raw == nil {
return 0
}
var s sdkstep.Step
if json.Unmarshal(raw, &s) != nil {
return 0
}
return s.Run
}
}