mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2025-12-30 13:19:44 -06:00
* handle started at differently * fix: start job runs in workflows controller * fix: keep job runs around for backwards compat
23 lines
386 B
Go
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()
|
|
}
|