The runner hears the builder's stream of build ends (kept last per subject, read whole at its start, A-181: consumes `mesh-delivery-builder.build.ended.**`) and keeps when each build ended, the stream's own time. wait-held carries it as `clock-from`, the bound of the wait is armed from it (30 minutes less what passed), and a bound whose build has not ended is armed when its end is heard, with wait-held said again. A failed end starts no clock. Builds: design 47 G §266, §269, §703, A-181, A-206 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"encoding/json"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
// BuildEnds are the done builds' ends heard from the builder's stream of build ends (event build.ended, kept last per subject
|
|
// and read whole at the start, design 47 G A-181): when each build, by module and fingerprint, ended, which is the time a held
|
|
// wait's bound counts from (§266, A-206).
|
|
type BuildEnds struct {
|
|
mu sync.Mutex
|
|
at map[string]time.Time
|
|
}
|
|
|
|
// buildEnd is the part of the body of build.ended the runner reads.
|
|
type buildEnd struct {
|
|
Module string `json:"module"`
|
|
Fingerprint string `json:"fingerprint"`
|
|
Outcome string `json:"outcome"`
|
|
}
|
|
|
|
// Heard keeps the end a message of the stream says, at the time the stream stamped it; a failed end, or a body naming no module
|
|
// and fingerprint, is kept for nothing. It says the module and fingerprint it kept.
|
|
func (e *BuildEnds) Heard(data []byte, at time.Time) (module, fp string, ok bool) {
|
|
var b buildEnd
|
|
if err := json.Unmarshal(data, &b); err != nil || b.Module == "" || b.Fingerprint == "" || b.Outcome == "failed" {
|
|
return "", "", false
|
|
}
|
|
e.mu.Lock()
|
|
defer e.mu.Unlock()
|
|
if e.at == nil {
|
|
e.at = map[string]time.Time{}
|
|
}
|
|
e.at[b.Module+"\x00"+b.Fingerprint] = at.UTC()
|
|
return b.Module, b.Fingerprint, true
|
|
}
|
|
|
|
// At is when the build of the module at the fingerprint ended, false when no end was heard.
|
|
func (e *BuildEnds) At(module, fp string) (time.Time, bool) {
|
|
e.mu.Lock()
|
|
defer e.mu.Unlock()
|
|
t, ok := e.at[module+"\x00"+fp]
|
|
return t, ok
|
|
}
|