Documentation
¶
Overview ¶
Package execution provides unified provider execution patterns for the MindTrial application. It handles common execution concerns such as retry logic, rate limiting, and error handling that are shared between different components like task runners and validators.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BackoffWithCallback ¶
func BackoffWithCallback(onBackoff func(nextRetryAttempt uint64, nextDelay time.Duration), next retry.Backoff) retry.Backoff
BackoffWithCallback wraps a retry.Backoff with a callback function that is called before each retry attempt. The callback receives the next retry attempt number and the delay duration.
Types ¶
type Attempt ¶
type Attempt func(ctx context.Context, execute func(providers.ExecutionEnvironment) (providers.Result, error)) (providers.Result, error)
Attempt wraps one provider execution attempt with optional attempt-scoped infrastructure. The execute callback runs the provider with the supplied environment; nil selects standalone execution.
func NewScopedAttempt ¶
func NewScopedAttempt(logger logging.Logger, newEnvironment func(context.Context) (ScopedEnvironment, error), keep func(ScopedEnvironment)) Attempt
NewScopedAttempt returns an Attempt that runs every attempt in a fresh environment created by newEnvironment. The environment of a failed or panicking attempt is closed; the environment of the successful attempt is passed to keep, which becomes responsible for closing it.
type Executor ¶
type Executor struct {
Provider providers.Provider
RunConfig config.RunConfig
// contains filtered or unexported fields
}
Executor provides a unified way to execute provider tasks with retry logic and rate limiting.
func NewExecutor ¶
func NewExecutor(provider providers.Provider, runConfig config.RunConfig, sharedLimiter *rate.Limiter) *Executor
NewExecutor creates a new provider executor with the given provider and run configuration. An optional shared rate limiter can be provided to enforce an aggregate rate limit across multiple executors (e.g., all runs within a provider). When both a shared limiter and a per-run limiter are configured, the shared limiter is checked first.
func (*Executor) Execute ¶
func (e *Executor) Execute(ctx context.Context, logger logging.Logger, task config.Task, attempt Attempt) (providers.Result, error)
Execute runs the task using the configured provider, applying retry logic and rate limiting as configured. Each attempt waits for rate-limit capacity before the attempt creates any attempt-scoped infrastructure. attempt may be nil for ordinary standalone execution.
type ScopedEnvironment ¶
type ScopedEnvironment interface {
providers.ExecutionEnvironment
// Close releases all resources of the environment.
Close(ctx context.Context) error
}
ScopedEnvironment is an attempt-scoped execution environment that must be closed by its owner.