Documentation
¶
Overview ¶
Package execution provides parallel multi-account execution primitives.
Package execution provides parallel multi-account execution primitives.
Index ¶
- Constants
- func Collect[T any](results []Result[T]) []T
- func CollectErrors[T any](results []Result[T]) []error
- func ConcurrencyFromEnv() int
- func FirstError[T any](results []Result[T]) error
- type AccountExecutor
- type Result
- func FanOut[T any](ctx context.Context, accountIDs []string, ...) []Result[T]
- func FanOutWithConcurrency[T any](ctx context.Context, accountIDs []string, ...) []Result[T]
- func Partition[T any](results []Result[T]) (successes, failures []Result[T])
- func RunForAccounts[T any](ctx context.Context, accounts []config.CloudAccount, fn AccountExecutor[T]) []Result[T]
- func RunForAccountsWithConcurrency[T any](ctx context.Context, accounts []config.CloudAccount, fn AccountExecutor[T], ...) []Result[T]
Constants ¶
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 CollectErrors ¶
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 ¶
FirstError returns the first non-nil error from results, or nil if all succeeded.
Types ¶
type AccountExecutor ¶
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 ¶
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 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.