diff --git a/go/declaration/declaration.go b/go/declaration/declaration.go index f7cb8832..33186099 100644 --- a/go/declaration/declaration.go +++ b/go/declaration/declaration.go @@ -921,6 +921,11 @@ type Process struct { // runtime of a build seat's holder, whose builds must never slow the operator's desktop. Absent: the machine's // defaults. For a process that stays up. Yields *Yields `json:"yields,omitempty"` + + // DrainBound is how long, in seconds, the process finishes the calls in flight once stopped before it exits + // (design 47 H2 §813 (12); H-A-358): the node-engine writes the unit's stop so the stop signal reaches this process + // alone and waits that long and the time its children take. Absent: none. For a process that stays up. + DrainBound int `json:"drain-bound,omitempty"` } // YieldIdle is the one priority a process yields at: the lowest there is. @@ -1024,6 +1029,13 @@ func (d *Process) validate(where string, _ bool) []string { problems = append(problems, where+": a witness judges a process that stays up; a step or a "+ "scheduled run is not running between its runs") } + if d.DrainBound < 0 { + problems = append(problems, fmt.Sprintf("%s: drain-bound is %d: a bound is seconds, none or more", where, d.DrainBound)) + } + if d.DrainBound > 0 && (d.RunOnce || d.Schedule != "") { + problems = append(problems, where+": drain-bound is for a process that stays up; a step or a scheduled run "+ + "is not stopped while it serves calls") + } if strings.ContainsAny(d.NotReversible, "\n\r") { problems = append(problems, where+": not-reversible is one line") } diff --git a/go/declaration/process_test.go b/go/declaration/process_test.go index 753771cd..754a5cb7 100644 --- a/go/declaration/process_test.go +++ b/go/declaration/process_test.go @@ -1,6 +1,7 @@ package declaration import ( + "encoding/json" "strings" "testing" ) @@ -99,6 +100,9 @@ func testTheModesAreExclusive(t *testing.T) { "an unknown priority": func(p *Process) { p.Yields = &Yields{Priority: "low"} }, "a share over the whole": func(p *Process) { p.Yields = &Yields{CPUShare: 150} }, "a yield saying nothing": func(p *Process) { p.Yields = &Yields{} }, + // Design 47 H2 §813 (12), H-A-358: a drain bound is seconds, for a process that stays up. + "a step with a drain bound": func(p *Process) { p.RunOnce = true; p.DrainBound = 30 }, + "a negative drain bound": func(p *Process) { p.DrainBound = -1 }, } { p := aProcess() bad(p) @@ -106,6 +110,18 @@ func testTheModesAreExclusive(t *testing.T) { t.Errorf("%s was accepted", name) } } + // It travels in the declaration under drain-bound, and so in its digest; absent says none. + up := aProcess() + up.DrainBound = 30 + if problems := up.validate("a process", false); len(problems) != 0 { + t.Errorf("a process that stays up with a drain bound was refused: %v", problems) + } + if b, _ := json.Marshal(up); !strings.Contains(string(b), `"drain-bound":30`) { + t.Errorf("the drain bound is not in the declaration: %s", b) + } + if b, _ := json.Marshal(aProcess()); strings.Contains(string(b), "drain-bound") { + t.Errorf("a process with no drain bound says one: %s", b) + } } // A cadence that is not a cadence is refused near its author, rather than by a machine at the far