{"modulePath":"github.com/LeanerCloud/cloud-commitments-platform","version":"v0.0.0-20261202160902-a99bcb5bfea3","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package execution\n\nPackage execution provides parallel multi-account execution primitives.\n\nPackage execution provides parallel multi-account execution primitives.\n\n## Constants\n\n```go\nconst DefaultMaxConcurrency = 20\n```\nDefaultMaxConcurrency is the default cap on parallel account goroutines. Override with FanOutWithConcurrency when a different limit is needed.\n\n## Functions\n\n```go\nfunc Collect[T any](results []Result[T]) []T\n```\nCollect aggregates the Value fields from all successful results into a flat slice.\n\n```go\nfunc CollectErrors[T any](results []Result[T]) []error\n```\nCollectErrors returns a slice of errors from failed results.\n\n```go\nfunc ConcurrencyFromEnv() int\n```\nConcurrencyFromEnv 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.\n\n```go\nfunc FirstError[T any](results []Result[T]) error\n```\nFirstError returns the first non-nil error from results, or nil if all succeeded.\n\n## Types\n\n```go\ntype AccountExecutor[T any] func(ctx context.Context, account config.CloudAccount) (T, error)\n```\nAccountExecutor is a function that performs an operation for a single account. It receives the full CloudAccount (with auth metadata) and returns a result.\n\n```go\ntype Result[T any] struct {\n\tValue     T\n\tErr       error\n\tAccountID string\n}\n```\nResult holds the outcome of running an operation against a single account.\n\n```go\nfunc FanOut[T any](\n\tctx context.Context,\n\taccountIDs []string,\n\tfn func(ctx context.Context, accountID string) (T, error),\n) []Result[T]\n```\nFanOut 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()).\n\nConcurrency 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.\n\n```go\nfunc FanOutWithConcurrency[T any](\n\tctx context.Context,\n\taccountIDs []string,\n\tfn func(ctx context.Context, accountID string) (T, error),\n\tmaxConcurrency int,\n) []Result[T]\n```\nFanOutWithConcurrency is like FanOut but with an explicit concurrency limit.\n\n```go\nfunc Partition[T any](results []Result[T]) (successes, failures []Result[T])\n```\nPartition splits a Result slice into successes and failures.\n\n```go\nfunc RunForAccounts[T any](\n\tctx context.Context,\n\taccounts []config.CloudAccount,\n\tfn AccountExecutor[T],\n) []Result[T]\n```\nRunForAccounts is a convenience wrapper over FanOut that takes CloudAccount values directly, using account.ID as the key in each Result.\n\n```go\nfunc RunForAccountsWithConcurrency[T any](\n\tctx context.Context,\n\taccounts []config.CloudAccount,\n\tfn AccountExecutor[T],\n\tmaxConcurrency int,\n) []Result[T]\n```\nRunForAccountsWithConcurrency is like RunForAccounts but with an explicit concurrency limit.\n\n","path":"github.com/LeanerCloud/cloud-commitments-platform/internal/execution","name":"execution","synopsis":"Package execution provides parallel multi-account execution primitives.","isRedistributable":true}
