Skip to content

Commit cd1078e

Browse files
committed
Try doing concurrent status checks for workloads
1 parent 75a29d8 commit cd1078e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

internal/status/queries.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"slices"
66

77
"github.com/nais/api/internal/workload"
8+
"github.com/sourcegraph/conc/pool"
89
)
910

1011
func ForWorkload(ctx context.Context, w workload.Workload) *WorkloadStatus {
@@ -31,9 +32,17 @@ func ForWorkload(ctx context.Context, w workload.Workload) *WorkloadStatus {
3132
}
3233

3334
func ForWorkloads[T workload.Workload](ctx context.Context, workloads []T) []WorkloadStatusError {
34-
var errs []WorkloadStatusError
35+
wg := pool.NewWithResults[[]WorkloadStatusError]().WithContext(ctx).WithMaxGoroutines(10)
3536
for _, workload := range workloads {
36-
errs = append(errs, ForWorkload(ctx, workload).Errors...)
37+
wg.Go(func(ctx context.Context) ([]WorkloadStatusError, error) {
38+
return ForWorkload(ctx, workload).Errors, nil
39+
})
40+
}
41+
42+
errors, _ := wg.Wait()
43+
var errs []WorkloadStatusError
44+
for _, e := range errors {
45+
errs = append(errs, e...)
3746
}
3847
return errs
3948
}

0 commit comments

Comments
 (0)