From 5ba0699adc0eed38f9216c7e307134244ffa9967 Mon Sep 17 00:00:00 2001 From: Julien Riou Date: Mon, 12 Apr 2021 09:21:24 +0200 Subject: [PATCH] Bugfix asynchronous loop When workers threshold was reached, the current parser was skipped instead of being processed later. Adding a for loop to retry instead. Signed-off-by: Julien Riou --- main.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index eb663d8..cf74b0e 100644 --- a/main.go +++ b/main.go @@ -197,14 +197,17 @@ func main() { jobsCount := 0 for _, parser := range parsers { - if jobsCount < *workers { - wg.Add(1) - jobsCount++ - go handleProducts(parser, notifiers, db, &wg) - } else { - log.Debugf("waiting for intermediate jobs to end") - wg.Wait() - jobsCount = 0 + for { + if jobsCount < *workers { + wg.Add(1) + jobsCount++ + go handleProducts(parser, notifiers, db, &wg) + break + } else { + log.Debugf("waiting for intermediate jobs to end") + wg.Wait() + jobsCount = 0 + } } }