From 1e7c059d128cfac8dd30c3679794e9a86de5eb19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Sat, 2 Mar 2024 22:09:53 +0100 Subject: [PATCH] Manager: check the farm status quickly after startup The database is polled every 30 seconds to determine the farm status; at startup the first poll is done after 1 second to get a faster status. Note that when jobs and workers change their status, the farm status is always updated. --- internal/manager/farmstatus/farmstatus.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/manager/farmstatus/farmstatus.go b/internal/manager/farmstatus/farmstatus.go index 82c440fd..5fd86d9d 100644 --- a/internal/manager/farmstatus/farmstatus.go +++ b/internal/manager/farmstatus/farmstatus.go @@ -55,15 +55,22 @@ func (s *Service) Run(ctx context.Context) { log.Debug().Msg("farm status: polling service running") defer log.Debug().Msg("farm status: polling service stopped") + // At startup the first poll should happen quickly. + waitTime := 1 * time.Second + for { select { case <-ctx.Done(): return - case <-time.After(pollWait): + case <-time.After(waitTime): s.poll(ctx) case <-s.forcePoll: s.poll(ctx) } + + // After the first poll we can go to a slower pace, as mostly the event bus + // is the main source of poll triggers. + waitTime = pollWait } }