Guard macOS Namespace fallback retries
This commit is contained in:
parent
e882a16dad
commit
dba641035b
3 changed files with 49 additions and 10 deletions
|
|
@ -52,6 +52,21 @@ func normalizeMacOSNSCMachineType(machineType string) (normalized string, change
|
|||
return normalized, changed, nil
|
||||
}
|
||||
|
||||
type macosNSCAttemptConfig struct {
|
||||
waitTimeout time.Duration
|
||||
createTimeout time.Duration
|
||||
}
|
||||
|
||||
func macosNSCAttemptConfigFor(index int, attempts []macosNSCAttemptConfig) macosNSCAttemptConfig {
|
||||
if len(attempts) == 0 {
|
||||
return macosNSCAttemptConfig{}
|
||||
}
|
||||
if index < len(attempts) {
|
||||
return attempts[index]
|
||||
}
|
||||
return attempts[len(attempts)-1]
|
||||
}
|
||||
|
||||
func (d *Dispatcher) launchMacOSRunnerViaNSC(ctx context.Context, runnerName string, req LaunchRequest, ttl time.Duration, machineType string) error {
|
||||
if machineType == "" {
|
||||
return errors.New("machine_type is required for macos runners")
|
||||
|
|
@ -92,17 +107,13 @@ func (d *Dispatcher) launchMacOSRunnerViaNSC(ctx context.Context, runnerName str
|
|||
}
|
||||
candidates = uniq
|
||||
|
||||
type attemptCfg struct {
|
||||
waitTimeout time.Duration
|
||||
createTimeout time.Duration
|
||||
}
|
||||
attempts := []attemptCfg{
|
||||
attempts := []macosNSCAttemptConfig{
|
||||
{waitTimeout: 6 * time.Minute, createTimeout: 8 * time.Minute},
|
||||
{waitTimeout: 4 * time.Minute, createTimeout: 6 * time.Minute},
|
||||
{waitTimeout: 3 * time.Minute, createTimeout: 5 * time.Minute},
|
||||
}
|
||||
|
||||
createInstance := func(mt string, a attemptCfg) (instanceID string, out string, err error) {
|
||||
createInstance := func(mt string, a macosNSCAttemptConfig) (instanceID string, out string, err error) {
|
||||
tmpDir, err := os.MkdirTemp("", "forgejo-nsc-macos-*")
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("mktemp: %w", err)
|
||||
|
|
@ -173,10 +184,7 @@ func (d *Dispatcher) launchMacOSRunnerViaNSC(ctx context.Context, runnerName str
|
|||
lastErr error
|
||||
)
|
||||
for i, mt := range candidates {
|
||||
a := attempts[i]
|
||||
if i >= len(attempts) {
|
||||
a = attempts[len(attempts)-1]
|
||||
}
|
||||
a := macosNSCAttemptConfigFor(i, attempts)
|
||||
|
||||
d.log.Info("launching Namespace macos runner via nsc",
|
||||
"runner", runnerName,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue