feat(parser): add result parser of createappinstance and added a configurable timeout for that function

This commit is contained in:
Richard Robert Reitz 2025-10-16 11:12:57 +02:00
parent 8f6fd94442
commit 0b31409b26
10 changed files with 218 additions and 47 deletions

View file

@ -4,6 +4,7 @@ package apply
import (
"context"
"errors"
"fmt"
"strings"
"sync"
@ -355,6 +356,15 @@ func (r *RecreateStrategy) executeInstanceActionWithRetry(ctx context.Context, a
}
lastErr = err
// Check if error is retryable (don't retry 4xx client errors)
if !isRetryableError(err) {
r.logf("Failed to %s instance %s: %v (non-retryable error, giving up)", operation, action.InstanceName, err)
result.Error = fmt.Errorf("non-retryable error: %w", err)
result.Duration = time.Since(startTime)
return result
}
if attempt < r.config.MaxRetries {
r.logf("Failed to %s instance %s: %v (will retry)", operation, action.InstanceName, err)
}
@ -395,6 +405,15 @@ func (r *RecreateStrategy) executeAppActionWithRetry(ctx context.Context, action
}
lastErr = err
// Check if error is retryable (don't retry 4xx client errors)
if !isRetryableError(err) {
r.logf("Failed to update app: %v (non-retryable error, giving up)", err)
result.Error = fmt.Errorf("non-retryable error: %w", err)
result.Duration = time.Since(startTime)
return result
}
if attempt < r.config.MaxRetries {
r.logf("Failed to update app: %v (will retry)", err)
}
@ -503,3 +522,27 @@ func (r *RecreateStrategy) logf(format string, v ...interface{}) {
r.logger.Printf("[RecreateStrategy] "+format, v...)
}
}
// isRetryableError determines if an error should be retried
// Returns false for client errors (4xx), true for server errors (5xx) and other transient errors
func isRetryableError(err error) bool {
if err == nil {
return false
}
// Check if it's an APIError with a status code
var apiErr *edgeconnect.APIError
if errors.As(err, &apiErr) {
// Don't retry client errors (4xx)
if apiErr.StatusCode >= 400 && apiErr.StatusCode < 500 {
return false
}
// Retry server errors (5xx)
if apiErr.StatusCode >= 500 {
return true
}
}
// Retry all other errors (network issues, timeouts, etc.)
return true
}