Files
hatchet/internal/queueutils/batch.go
abelanger5 8939c94f63 fix: send fewer messages to job queue when it's not necessary (#932)
* handle started at differently

* fix: start job runs in workflows controller

* fix: keep job runs around for backwards compat
2024-10-03 07:39:06 -04:00

23 lines
386 B
Go

package queueutils
import "golang.org/x/sync/errgroup"
func MakeBatched[T any](batchSize int, things []T, fn func(group []T) error) error {
g := new(errgroup.Group)
for i := 0; i < len(things); i += batchSize {
end := i + batchSize
if end > len(things) {
end = len(things)
}
group := things[i:end]
g.Go(func() error {
return fn(group)
})
}
return g.Wait()
}