Documentation
¶
Overview ¶
Package retry provides build retry management functionality.
Index ¶
- Constants
- Variables
- func IsValidationError(err error) bool
- type BuildAttempt
- type FallbackNotification
- type Manager
- func (m *Manager) ClearAttempts(buildID string)
- func (m *Manager) GetAttempts(buildID string) []BuildAttempt
- func (m *Manager) GetBackoffDuration() time.Duration
- func (m *Manager) GetLastAttempt(buildID string) *BuildAttempt
- func (m *Manager) GetMaxAttempts() int
- func (m *Manager) IsOCIFallbackError(err error) bool
- func (m *Manager) IsRetryableError(err error) bool
- func (m *Manager) PrepareRetry(ctx context.Context, job *models.BuildJob) (*models.BuildJob, error)
- func (m *Manager) RecordAttempt(ctx context.Context, buildID string, attempt BuildAttempt) error
- func (m *Manager) ShouldRetry(ctx context.Context, job *models.BuildJob, err error) bool
- type ManagerOption
- type RetryStrategy
Constants ¶
const MaxRetries = 2
MaxRetries is the default maximum retry count. **Validates: Requirements 15.5**
Variables ¶
var ( // ErrMaxRetriesExceeded is returned when the maximum number of retries has been exceeded. ErrMaxRetriesExceeded = errors.New("maximum retry attempts exceeded") // ErrNonRetryableError is returned when an error is not retryable. ErrNonRetryableError = errors.New("error is not retryable") // ErrInvalidJob is returned when a job is invalid for retry. ErrInvalidJob = errors.New("invalid job for retry") // ErrBuildIDRequired is returned when a build ID is required but not provided. ErrBuildIDRequired = errors.New("build ID is required") )
Retry manager errors.
var ErrValidationFailed = errors.New("build validation failed")
ErrValidationFailed is the sentinel error for validation failures. This error type should never trigger a retry. **Validates: Requirements 15.7**
Functions ¶
func IsValidationError ¶
IsValidationError checks if an error is a validation error. Validation errors should never trigger a retry. **Validates: Requirements 15.7**
Types ¶
type BuildAttempt ¶
type BuildAttempt struct {
AttemptNumber int `json:"attempt_number"`
Strategy models.BuildStrategy `json:"strategy"`
BuildType models.BuildType `json:"build_type"`
StartedAt time.Time `json:"started_at"`
CompletedAt *time.Time `json:"completed_at,omitempty"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
BuildAttempt records a single build attempt.
type FallbackNotification ¶
type FallbackNotification struct {
BuildID string `json:"build_id"`
OriginalType string `json:"original_type"`
FallbackType string `json:"fallback_type"`
Reason string `json:"reason"`
AttemptNumber int `json:"attempt_number"`
Timestamp time.Time `json:"timestamp"`
}
FallbackNotification contains information about a build fallback.
type Manager ¶
type Manager struct {
// NotificationCallback is called when a fallback occurs
NotificationCallback func(notification *FallbackNotification)
// contains filtered or unexported fields
}
Manager handles build retry logic.
func NewManager ¶
func NewManager(opts ...ManagerOption) *Manager
NewManager creates a new retry manager.
func (*Manager) ClearAttempts ¶
ClearAttempts clears all recorded attempts for a build.
func (*Manager) GetAttempts ¶
func (m *Manager) GetAttempts(buildID string) []BuildAttempt
GetAttempts returns all recorded attempts for a build.
func (*Manager) GetBackoffDuration ¶
GetBackoffDuration returns the backoff duration for retries.
func (*Manager) GetLastAttempt ¶
func (m *Manager) GetLastAttempt(buildID string) *BuildAttempt
GetLastAttempt returns the most recent attempt for a build.
func (*Manager) GetMaxAttempts ¶
GetMaxAttempts returns the maximum number of retry attempts.
func (*Manager) IsOCIFallbackError ¶
IsOCIFallbackError checks if an error should trigger OCI fallback.
func (*Manager) IsRetryableError ¶
IsRetryableError checks if an error matches any retryable pattern.
func (*Manager) PrepareRetry ¶
PrepareRetry prepares a job for retry, potentially switching to OCI.
func (*Manager) RecordAttempt ¶
RecordAttempt records a build attempt.
type ManagerOption ¶
type ManagerOption func(*Manager)
ManagerOption is a functional option for configuring the Manager.
func WithNotificationCallback ¶
func WithNotificationCallback(callback func(*FallbackNotification)) ManagerOption
WithNotificationCallback sets the callback for fallback notifications.
func WithRetryStrategy ¶
func WithRetryStrategy(strategy *RetryStrategy) ManagerOption
WithRetryStrategy sets a custom retry strategy.
type RetryStrategy ¶
type RetryStrategy struct {
MaxAttempts int `json:"max_attempts"` // Default: 2
RetryAsOCI bool `json:"retry_as_oci"` // Try OCI on pure-nix failure
RetryableErrors []string `json:"retryable_errors"` // Error codes that trigger retry
BackoffDuration time.Duration `json:"backoff_duration"` // Wait between retries
}
RetryStrategy defines retry behavior.
func DefaultRetryStrategy ¶
func DefaultRetryStrategy() *RetryStrategy
DefaultRetryStrategy returns the default retry strategy.