execution

package
v0.0.0-...-4c22e88 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: OSL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package execution provides parallel multi-account execution primitives.

Package execution provides parallel multi-account execution primitives.

Index

Constants

View Source
const DefaultMaxConcurrency = 20

DefaultMaxConcurrency is the default cap on parallel account goroutines. Override with FanOutWithConcurrency when a different limit is needed.

Variables

This section is empty.

Functions

func Collect

func Collect[T any](results []Result[T]) []T

Collect aggregates the Value fields from all successful results into a flat slice.

func CollectErrors

func CollectErrors[T any](results []Result[T]) []error

CollectErrors returns a slice of errors from failed results.

func ConcurrencyFromEnv

func ConcurrencyFromEnv() int

ConcurrencyFromEnv reads the CUDLY_MAX_ACCOUNT_PARALLELISM env var and returns its value when it's a positive integer, otherwise DefaultMaxConcurrency. Shared between the purchase manager (which drives live cloud API calls) and the scheduler (per-account recommendations collection) so both honor the same operator-level override.

func FirstError

func FirstError[T any](results []Result[T]) error

FirstError returns the first non-nil error from results, or nil if all succeeded.

Types

type AccountExecutor

type AccountExecutor[T any] func(ctx context.Context, account config.CloudAccount) (T, error)

AccountExecutor is a function that performs an operation for a single account. It receives the full CloudAccount (with auth metadata) and returns a result.

type Result

type Result[T any] struct {
	Value     T
	Err       error
	AccountID string
}

Result holds the outcome of running an operation against a single account.

func FanOut

func FanOut[T any](
	ctx context.Context,
	accountIDs []string,
	fn func(ctx context.Context, accountID string) (T, error),
) []Result[T]

FanOut runs fn concurrently for each accountID in the supplied slice and collects all results. Cancellation of ctx is respected: inflight goroutines see the canceled context but all launched goroutines are still awaited so the caller receives a full result slice (some entries may carry ctx.Err()).

Concurrency is capped at DefaultMaxConcurrency to avoid overwhelming AWS STS rate limits and Lambda memory budgets on large organizations. The order of results is non-deterministic.

func FanOutWithConcurrency

func FanOutWithConcurrency[T any](
	ctx context.Context,
	accountIDs []string,
	fn func(ctx context.Context, accountID string) (T, error),
	maxConcurrency int,
) []Result[T]

FanOutWithConcurrency is like FanOut but with an explicit concurrency limit.

func Partition

func Partition[T any](results []Result[T]) (successes, failures []Result[T])

Partition splits a Result slice into successes and failures.

func RunForAccounts

func RunForAccounts[T any](
	ctx context.Context,
	accounts []config.CloudAccount,
	fn AccountExecutor[T],
) []Result[T]

RunForAccounts is a convenience wrapper over FanOut that takes CloudAccount values directly, using account.ID as the key in each Result.

func RunForAccountsWithConcurrency

func RunForAccountsWithConcurrency[T any](
	ctx context.Context,
	accounts []config.CloudAccount,
	fn AccountExecutor[T],
	maxConcurrency int,
) []Result[T]

RunForAccountsWithConcurrency is like RunForAccounts but with an explicit concurrency limit.

Jump to

Keyboard shortcuts

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