41 lines
1.5 KiB
Go
41 lines
1.5 KiB
Go
package steprun
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// AgainDelaysSetting is the setting each build module declares for the delay it passes with a run's `again` (design 47
|
|
// H2 §799): how long the bus waits before it gives an ask again after its first, then its second run ended on a
|
|
// transport fault, as Go durations separated by commas. DefaultAgainDelays is its default, so three runs span the tool runner's restart, 105 s (design 47 H2 H-A-603).
|
|
const (
|
|
AgainDelaysSetting = "again-delays"
|
|
DefaultAgainDelays = "15s,90s"
|
|
)
|
|
|
|
// AgainDelays reads the setting again-delays into a Puller's Delay (§799): the run-th delay of the list, its last for a
|
|
// run past it; an empty setting is DefaultAgainDelays. A delay that is no positive duration is an error naming it.
|
|
func AgainDelays(setting string) (func(run int) time.Duration, error) {
|
|
if strings.TrimSpace(setting) == "" {
|
|
setting = DefaultAgainDelays
|
|
}
|
|
var delays []time.Duration
|
|
for _, w := range strings.Split(setting, ",") {
|
|
d, err := time.ParseDuration(strings.TrimSpace(w))
|
|
if err != nil || d <= 0 {
|
|
return nil, fmt.Errorf("the setting %s holds %q, whose %q is not a positive duration", AgainDelaysSetting, setting, w)
|
|
}
|
|
delays = append(delays, d)
|
|
}
|
|
return func(run int) time.Duration {
|
|
if run < 1 {
|
|
run = 1
|
|
}
|
|
return delays[min(run, len(delays))-1]
|
|
}, nil
|
|
}
|
|
|
|
// defaultAgainDelay is DefaultAgainDelays read, a Puller's delay when it names none.
|
|
var defaultAgainDelay, _ = AgainDelays(DefaultAgainDelays)
|