All of mesh-build-go's buildstep Go module leaves mesh-catalog for modules/mesh-delivery-sdk: the step run, fetch and release and the regenerate-and-compare step as the package steprun, the CPU share as steprun/buildcpu, the conformance kit as steprun/conformance, the seat generator as seatgen with cmd/seatgen, and cmd/mesh-pack. The three build modules and the builder's and checker's tests import the SDK and keep no copy; the SDK requires nothing of mesh-catalog. Code the build modules share is the delivery domain's SDK, not one module's package. It carries the build-module round's two new files of that package (dropdetected.go 247c422f, storedbuilds.go 904b8aed). Builds: design 47 G §464, §680, §327, §420, §495 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
58 lines
1.8 KiB
Go
58 lines
1.8 KiB
Go
package steprun
|
|
|
|
import (
|
|
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
|
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
// NodeCapacity is the node's build capacity, read from the module's settings file at path at every call, so a change
|
|
// takes effect at the next pull. No path, no file value, or a value that is not a whole number of at least 0 gives 0 and
|
|
// a value that cannot be read says why: pulling on a setting nobody can read could build on a node that must not.
|
|
func NodeCapacity(path, node string, logf func(string, ...any)) func() int {
|
|
say := func(format string, args ...any) {
|
|
if logf != nil {
|
|
logf(format, args...)
|
|
}
|
|
}
|
|
return func() int {
|
|
n, err := ReadCapacity(path)
|
|
if err != nil {
|
|
say("%v, so %s pulls nothing", err, node)
|
|
return 0
|
|
}
|
|
return n
|
|
}
|
|
}
|
|
|
|
// ReadCapacity is the capacity the settings file at path holds, and why it cannot be read when it cannot (then 0).
|
|
func ReadCapacity(path string) (int, error) {
|
|
if path == "" {
|
|
return 0, nil
|
|
}
|
|
raw, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return 0, fmt.Errorf("the build capacity cannot be read: %w", err)
|
|
}
|
|
var s map[string]json.RawMessage
|
|
if err := json.Unmarshal(raw, &s); err != nil {
|
|
return 0, fmt.Errorf("the settings file %s is not JSON: %w", path, err)
|
|
}
|
|
return capacityOf(s[sdkstep.CapacitySetting])
|
|
}
|
|
|
|
// capacityOf is the capacity a config value holds: absent or null is 0; anything but a whole number of at least 0 is
|
|
// refused, naming it.
|
|
func capacityOf(value json.RawMessage) (int, error) {
|
|
if len(value) == 0 || string(value) == "null" {
|
|
return 0, nil
|
|
}
|
|
var n int
|
|
if err := json.Unmarshal(value, &n); err != nil || n < 0 {
|
|
return 0, fmt.Errorf("the build capacity %s is not a whole number of asks at once, 0 or more", value)
|
|
}
|
|
return n, nil
|
|
}
|