Files
mesh-delivery/modules/mesh-delivery-pipeline/internal/pipeline/released.go
T
jschoubben 33feb148ce H-A-479 (1) runner: start with modules starts a failed mover again at the head
A module whose pipeline failed at an unchanged entry was never carried again
until its fingerprint moved, since start refused the head whose pipeline
existed. The start verb now takes modules: the named modules whose newest
entry has no passed pipeline are started at the head's revision, at the
take-in's tiers, keyed <branch>.<revision>.again.<n> (n from 1, written on
absence); a module whose newest entry passed, or that the head holds no
entry of, is refused by name, nothing started. Exactly one of module or
modules is given. The new key form is read by every key-form list (the
sweep's, a release's, the mover keys'). The runner seat's form is 8; the
contract is regenerated.

Builds: design 47 H2 H-A-479, H-A-479 addendum (1)
2026-11-22 16:05:27 +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 + ".*", b + ".*." + againToken + ".*"} {
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 ""
}