retry

package
v0.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package retry provides build retry management functionality.

Index

Constants

View Source
const MaxRetries = 2

MaxRetries is the default maximum retry count. **Validates: Requirements 15.5**

Variables

View Source
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.

View Source
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

func IsValidationError(err error) bool

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

func (m *Manager) ClearAttempts(buildID string)

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

func (m *Manager) GetBackoffDuration() time.Duration

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

func (m *Manager) GetMaxAttempts() int

GetMaxAttempts returns the maximum number of retry attempts.

func (*Manager) IsOCIFallbackError

func (m *Manager) IsOCIFallbackError(err error) bool

IsOCIFallbackError checks if an error should trigger OCI fallback.

func (*Manager) IsRetryableError

func (m *Manager) IsRetryableError(err error) bool

IsRetryableError checks if an error matches any retryable pattern.

func (*Manager) PrepareRetry

func (m *Manager) PrepareRetry(ctx context.Context, job *models.BuildJob) (*models.BuildJob, error)

PrepareRetry prepares a job for retry, potentially switching to OCI.

func (*Manager) RecordAttempt

func (m *Manager) RecordAttempt(ctx context.Context, buildID string, attempt BuildAttempt) error

RecordAttempt records a build attempt.

func (*Manager) ShouldRetry

func (m *Manager) ShouldRetry(ctx context.Context, job *models.BuildJob, err error) bool

ShouldRetry determines if a failed build should be retried. **Validates: Requirements 15.5, 15.7**

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL