E7: stop the tool runner alone and wait its drain bound
The service manager's stop signalled the tool runner's whole group, so its bundles died with their calls. The composer carries the runner's drain-bound setting on its process; the unit stops the runner alone and waits the bound and 15 s before it kills what is left, so the new runner starts only after the old one exits or that bound passes. Builds: design 47 H2 §813 (12); H-A-353; H-A-358
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
@@ -171,12 +172,17 @@ func resolutionRuntimeProcess(r mcat.Resolution, with mcat.Rendering, h Holding)
|
||||
}
|
||||
env[mcat.RuntimeToolEnv] = string(body)
|
||||
}
|
||||
drain, err := drainBoundOf(*runtime, with.Settings[runtime.Module])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
process := map[string]any{
|
||||
"id": runtime.Module + "." + RuntimeProcessID(), "type": "process", "name": runtime.Module,
|
||||
"source": bundle.Source, "digest": bundle.Digest,
|
||||
"run": run,
|
||||
"env": env,
|
||||
"restart-on": toAny(restartOn),
|
||||
"run": run,
|
||||
"env": env,
|
||||
"restart-on": toAny(restartOn),
|
||||
"drain-bound": drain,
|
||||
}
|
||||
if r.Account != "" {
|
||||
env[mcat.RuntimeOperatorAccount] = r.Account
|
||||
@@ -195,6 +201,44 @@ func resolutionRuntimeProcess(r mcat.Resolution, with mcat.Rendering, h Holding)
|
||||
return process, nil
|
||||
}
|
||||
|
||||
// DrainBoundSetting is the tool runner module's setting of how long, in seconds, it finishes its calls in flight once
|
||||
// stopped (design 47 H2 §813 (12)); DefaultDrainBound is its default where no layer sets it (H-A-358).
|
||||
const (
|
||||
DrainBoundSetting = "drain-bound"
|
||||
DefaultDrainBound = 30
|
||||
)
|
||||
|
||||
// drainBoundOf is the tool runner's drain bound in seconds, from its setting drain-bound, else DefaultDrainBound (design
|
||||
// 47 H2 §813 (12), H-A-358): the node-engine writes its unit's stop from it. A value that is no whole number of seconds
|
||||
// above zero is refused by name.
|
||||
func drainBoundOf(m mcat.Manifest, layers []mcat.Layer) (int, error) {
|
||||
v, set := settingValue(WithDefaults(m, layers), DrainBoundSetting)
|
||||
if !set {
|
||||
return DefaultDrainBound, nil
|
||||
}
|
||||
var n float64
|
||||
switch x := v.(type) {
|
||||
case float64:
|
||||
n = x
|
||||
case int:
|
||||
n = float64(x)
|
||||
case int64:
|
||||
n = float64(x)
|
||||
case string:
|
||||
parsed, err := strconv.Atoi(strings.TrimSpace(x))
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("%s's setting %s is %q, and it is a whole number of seconds", m.Module, DrainBoundSetting, x)
|
||||
}
|
||||
n = float64(parsed)
|
||||
default:
|
||||
return 0, fmt.Errorf("%s's setting %s is %v, and it is a whole number of seconds", m.Module, DrainBoundSetting, v)
|
||||
}
|
||||
if n < 1 || n != float64(int(n)) {
|
||||
return 0, fmt.Errorf("%s's setting %s is %v, and it is a whole number of seconds above zero", m.Module, DrainBoundSetting, v)
|
||||
}
|
||||
return int(n), nil
|
||||
}
|
||||
|
||||
// NoRuntimeToRunError is a module of its own account with no runtime program on its node to run it from. Held says the
|
||||
// runtime is there and held (its stand-in, Stubbed): the module cannot compose because the runtime does not, so a
|
||||
// composition that holds the runtime holds it too, never the node (issue 774).
|
||||
|
||||
Reference in New Issue
Block a user