From b958e845727cad3868428cc1ccb34b586c4da3bc Mon Sep 17 00:00:00 2001 From: Henry Dollman Date: Tue, 6 Aug 2024 18:15:12 -0400 Subject: [PATCH] fix: down systems jamming the system update queue --- hub/main.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hub/main.go b/hub/main.go index c8eed32..9364bac 100644 --- a/hub/main.go +++ b/hub/main.go @@ -235,12 +235,18 @@ func updateSystems() { } fiftySecondsAgo := time.Now().UTC().Add(-50 * time.Second) batchSize := len(records)/4 + 1 - for i := 0; i < batchSize; i++ { - if records[i].GetDateTime("updated").Time().After(fiftySecondsAgo) { + done := 0 + for _, record := range records { + // break if batch size reached or if the system was updated less than 50 seconds ago + if done >= batchSize || record.GetDateTime("updated").Time().After(fiftySecondsAgo) { break } - // log.Println("updating", records[i].Get(("name"))) - go updateSystem(records[i]) + // don't increment for down systems to avoid them jamming the queue + // because they're always first when sorted by least recently updated + if record.GetString("status") != "down" { + done++ + } + go updateSystem(record) } }