package buildstep import ( "encoding/json" "os" "git.novox.be/novox/mesh-sdk/go/buildcpu" ) // NodeLimits is what one step on node is held to (novox/hq issue 1806): the node's processor cap from the module's // settings file at path (buildcpu.Setting, its default when the file does not set it), the machine's processors, and // the node's capacity, so the steps that run at once start no more threads together than the cap gives. Read at every // call, like the capacity, so a change takes effect at the next step. A file or a setting that cannot be read gives the // default cap and says why: a step still runs with a bound, never without one. func NodeLimits(path, node string, slots int, logf func(string, ...any)) buildcpu.Limits { setting := buildcpu.Defaults if path != "" { if raw, err := os.ReadFile(path); err != nil { sayTo(logf, "the processor cap cannot be read, so %s builds under the default cap: %v", node, err) } else { var s map[string]any if err := json.Unmarshal(raw, &s); err != nil { sayTo(logf, "the settings file %s is not JSON, so %s builds under the default cap: %v", path, node, err) } else if v, ok := s[buildcpu.Setting].(string); ok { setting = v } } } l, err := buildcpu.LimitsFor(setting, node, slots) if err != nil { sayTo(logf, "%v, so %s builds under the default cap of %d%%", err, node, buildcpu.DefaultPercent) } return l } func sayTo(logf func(string, ...any), format string, args ...any) { if logf != nil { logf(format, args...) } }