From 6d0140151b44752a7961a664113abd279b061937 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Thu, 16 Mar 2023 12:01:04 -0400 Subject: [PATCH] make sure we get all of it --- internal/cmd/scheduler.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/cmd/scheduler.go b/internal/cmd/scheduler.go index 5bfc42f..440e4fd 100644 --- a/internal/cmd/scheduler.go +++ b/internal/cmd/scheduler.go @@ -3,6 +3,7 @@ package cmd import ( "context" "fmt" + "math" "net/http" _ "net/http/pprof" "strconv" @@ -484,10 +485,14 @@ func enqueueAccounts(ctx context.Context, logger *zap.Logger, statsd *statsd.Cli } chunks := [][]string{} + chunkSize := int(math.Ceil(float64(len(ids)) / float64(accountEnqueueSeconds))) for i := 0; i < accountEnqueueSeconds; i++ { - min := (i * len(ids) / accountEnqueueSeconds) - max := ((i + 1) * len(ids)) / accountEnqueueSeconds - chunks = append(chunks, ids[min:max]) + left := i * chunkSize + right := (i + 1) * chunkSize + if right > len(ids) { + right = len(ids) + } + chunks = append(chunks, ids[left:right]) } _ = statsd.Histogram("apollo.queue.runtime", float64(time.Since(now).Milliseconds()), []string{"queue:notifications"}, 1)