wait

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateNextInterval

func CalculateNextInterval(attempt int, config BackoffConfig) time.Duration

CalculateNextInterval calculates the next retry interval using exponential backoff The formula is: interval = min(min_interval * (multiplier ^ attempt), max_interval) Attempt is zero-indexed (first retry is attempt 0)

Types

type BackoffConfig

type BackoffConfig struct {
	MinInterval  time.Duration // Minimum interval between retries
	MaxInterval  time.Duration // Maximum interval between retries
	Multiplier   float64       // Exponential backoff multiplier
	InitialDelay time.Duration // Delay before first attempt
}

BackoffConfig configures the exponential backoff strategy

func DefaultBackoffConfig

func DefaultBackoffConfig() BackoffConfig

DefaultBackoffConfig returns the default backoff configuration

func (BackoffConfig) Validate

func (c BackoffConfig) Validate() error

Validate validates the backoff configuration

type Condition

type Condition struct {
	Type     ConditionType
	Operator Operator
	Value    int64
}

Condition represents a success condition for waiting

func ParseCondition

func ParseCondition(s string) (Condition, error)

ParseCondition parses a condition string in kubectl-like format Supported formats:

  • count=N (exactly N records)
  • count-gte=N (at least N records, >=)
  • count-gt=N (more than N records, >)
  • count-lte=N (at most N records, <=)
  • count-lt=N (fewer than N records, <)
  • any (any records, count > 0)
  • none (no records, count == 0)

func (Condition) Evaluate

func (c Condition) Evaluate(recordCount int64) bool

Evaluate evaluates the condition against a record count

func (Condition) String

func (c Condition) String() string

String returns a human-readable representation of the condition

type ConditionType

type ConditionType string

ConditionType defines the type of condition

const (
	ConditionTypeCount ConditionType = "count"
	ConditionTypeAny   ConditionType = "any"
	ConditionTypeNone  ConditionType = "none"
)

type Operator

type Operator string

Operator defines the comparison operator

const (
	OpEqual        Operator = "=="
	OpGreaterEqual Operator = ">="
	OpGreater      Operator = ">"
	OpLessEqual    Operator = "<="
	OpLess         Operator = "<"
)

type QueryWaiter

type QueryWaiter struct {
	// contains filtered or unexported fields
}

QueryWaiter polls a query until a condition is met

func NewQueryWaiter

func NewQueryWaiter(executor *exec.DQLExecutor, config WaitConfig) *QueryWaiter

NewQueryWaiter creates a new query waiter

func (*QueryWaiter) PrintResults

func (w *QueryWaiter) PrintResults(result *Result) error

PrintResults prints the query results if output format is specified

func (*QueryWaiter) Wait

func (w *QueryWaiter) Wait(ctx context.Context) (*Result, error)

Wait executes the wait operation

type Result

type Result struct {
	Success       bool
	Attempts      int
	Elapsed       time.Duration
	RecordCount   int64
	Records       []map[string]any
	FailureReason string
}

Result contains the result of a wait operation

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError represents a validation error for backoff configuration

func (*ValidationError) Error

func (e *ValidationError) Error() string

type WaitConfig

type WaitConfig struct {
	Query        string
	Condition    Condition
	Timeout      time.Duration
	MaxAttempts  int // 0 = unlimited
	Backoff      BackoffConfig
	QueryOptions exec.DQLExecuteOptions
	OutputFormat string
	Quiet        bool
	Verbose      bool
	ProgressOut  io.Writer // Where to write progress messages (default: os.Stderr, even if Out is set)
	Out          io.Writer // Where PrintResults writes (default: os.Stdout); progress goes to ProgressOut
}

WaitConfig configures the wait operation

Jump to

Keyboard shortcuts

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