29 lines
937 B
Go
29 lines
937 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"git.novox.be/novox/mesh-sdk/go/delivery/buildrun"
|
|
"os"
|
|
)
|
|
|
|
// capacityFrom is the build capacity of each node (ADR 0478 clause 3): the module's setting `capacity`, `<node>=<steps at
|
|
// once>` pairs separated by commas, laid into the settings file the controller composes (issue 1661); empty is one step at a
|
|
// time on every node. With no settings file named, fallback is read instead, for a run outside the module's launch.
|
|
func capacityFrom(path, fallback string) (map[string]int, error) {
|
|
if path == "" {
|
|
return buildrun.ParseCapacity(fallback)
|
|
}
|
|
raw, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("the settings file: %w", err)
|
|
}
|
|
var s struct {
|
|
Capacity string `json:"capacity"`
|
|
}
|
|
if err := json.Unmarshal(raw, &s); err != nil {
|
|
return nil, fmt.Errorf("the settings file %s is not JSON: %w", path, err)
|
|
}
|
|
return buildrun.ParseCapacity(s.Capacity)
|
|
}
|