Files
mesh-delivery/modules/mesh-delivery-pipeline/internal/pipeline/released.go
T
jschoubben 62e8274bf9 R5: a mover left unfinished by another's failure is put in a pipeline again
A pipeline ending failed or cancelled keeps each mover whose own required
steps passed or never ran in the runner's state unfinished and names it in
pipeline-ended's unfinished; the branch's next kept catalog revision carries
it, or starts a pipeline for it alone. runner_unfinished reads the state,
runner_unfinished_drop drops one key, runner_unfinished_place asks the new
seat verb place-unfinished (contracts regenerated), both hand acts.

Builds: design 47 H2 §786, §820 (unfinished), H-A-398
2026-11-22 01:02:58 +01:00

108 lines
4.1 KiB
Go

package pipeline
import (
"errors"
"fmt"
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
"git.novox.be/novox/mesh-sdk/go/keys"
)
// Released writes a version-released's version into the entry of the mover it names (design 47 H §746, H-A-52): the mover of
// that module in each pipeline of the source revision built, a run's aside, so its pipeline-ended names the released version.
// branch, when not empty, is the one watched branch the version was released for (H-A-62); empty matches every branch's
// pipeline of that source. A pipeline that ended passed says its end again, naming the version, and again whenever the version
// is heard again (H-A-270 (2), H-A-277). It says how many movers it wrote.
func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int, error) {
if ev.Module == "" || ev.Version == "" || ev.Source <= 0 {
return 0, fmt.Errorf("a version-released names its module, version and source revision: %+v", ev)
}
b := "*"
if branch != "" {
b = keys.EscapeName(branch)
}
// A pipeline is keyed by its revision (H-A-213 (4)), so the pipelines of a source are those naming it, of either key
// form a source's pipelines were kept under.
var pkeys []string
for _, f := range []string{b + ".*", b + ".*.published.*.*", b + ".*." + unfinishedToken + ".*"} {
k, err := h.Store.Keys(f)
if err != nil {
return 0, fmt.Errorf("the pipelines of source %d are not listed: %w", ev.Source, err)
}
pkeys = append(pkeys, k...)
}
wrote := 0
for _, key := range pkeys {
for {
p, rev, err := h.Store.Get(key)
if err != nil {
return wrote, fmt.Errorf("the pipeline %s is not read: %w", key, err)
}
if p.Source != ev.Source || p.Run != "" {
break
}
i := -1
for j, m := range p.Movers {
if m.Module == ev.Module {
i = j
}
}
if i < 0 {
break
}
if p.Movers[i].Version == ev.Version {
// A version heard again says the end of an ended passed pipeline again (H-A-277 (3)): a say that failed after
// the version was written is said now; taking it again is a no-op for the holder.
if err := h.sayEndedAgain(key, p, ev); err != nil {
return wrote, err
}
break
}
p.Movers[i].Version = ev.Version
if _, err := h.Store.Update(key, p, rev); errors.Is(err, ErrChanged) {
continue
} else if err != nil {
return wrote, fmt.Errorf("the pipeline %s cannot be written: %w", key, err)
}
wrote++
// A version written after the pipeline's end was said says that end again (H-A-270 (2)): the same pipeline-ended,
// now naming the version, so the seat mesh-wants' holder takes the mover it skipped; taking a mover again is a no-op.
if err := h.sayEndedAgain(key, p, ev); err != nil {
return wrote, err
}
break
}
}
if wrote == 0 {
h.logf("the version %s of %s at source %d names no mover of a pipeline here", ev.Version, ev.Module, ev.Source)
}
return wrote, nil
}
// sayEndedAgain says p's pipeline-ended again when p ended passed (H-A-270 (2), H-A-277 (2)): only a passed end writes a want,
// so a superseded, cancelled or failed one is not said again.
func (h *Hearer) sayEndedAgain(key string, p seat.Pipeline, ev catalog.VersionReleasedEvent) error {
if p.Ended == nil || p.Outcome != seat.PipelineOutcomePassed {
return nil
}
if err := h.say(seat.EventPipelineEnded, p, nil); err != nil {
return fmt.Errorf("the version %s of %s is in the ended pipeline %s but its %s is not said again: %w",
ev.Version, ev.Module, key, seat.EventPipelineEnded, err)
}
h.logf("%s: the version %s of %s is written after its end: %s said again", key, ev.Version, ev.Module, seat.EventPipelineEnded)
return nil
}
// ReleasedBranch is the watched branch a module's versions are released for, its registration's first (H-A-62); empty when
// the registration is not held.
func ReleasedBranch(reg func(string) (catalog.Registration, bool), module string) string {
if reg == nil {
return ""
}
if r, ok := reg(module); ok && len(r.Branches) > 0 {
return r.Branches[0]
}
return ""
}