From ae481c527800365267b725afe3587ec1ca0f174e Mon Sep 17 00:00:00 2001 From: Kevin Franklin Kim Date: Fri, 22 Mar 2024 16:26:34 +0100 Subject: [PATCH] refactor: mark loaded --- pkg/repo/loader.go | 10 +++++++++- pkg/repo/repo.go | 26 +++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pkg/repo/loader.go b/pkg/repo/loader.go index 6f35553..47551b6 100644 --- a/pkg/repo/loader.go +++ b/pkg/repo/loader.go @@ -65,7 +65,15 @@ func (r *Repo) UpdateRoutine(ctx context.Context) error { l.Error("update failed", zap.Error(err)) metrics.UpdatesFailedCounter.WithLabelValues().Inc() } else { - l.Info("update success") + if !r.Loaded() { + r.loaded.Store(true) + l.Info("initial update success") + if r.onStart != nil { + r.onStart() + } + } else { + l.Info("update success") + } metrics.UpdatesCompletedCounter.WithLabelValues().Inc() } diff --git a/pkg/repo/repo.go b/pkg/repo/repo.go index 909b849..a920b5e 100644 --- a/pkg/repo/repo.go +++ b/pkg/repo/repo.go @@ -26,16 +26,15 @@ const maxGetURIForNodeRecursionLevel = 1000 // Repo content repository type ( Repo struct { - l *zap.Logger - url string - poll bool - pollInterval time.Duration - pollVersion string - onStart func() - loaded *atomic.Bool - history *History - httpClient *http.Client - // updateLock sync.Mutex + l *zap.Logger + url string + poll bool + pollInterval time.Duration + pollVersion string + onStart func() + loaded *atomic.Bool + history *History + httpClient *http.Client dimensionUpdateChannel chan *RepoDimension dimensionUpdateDoneChannel chan error updateInProgressChannel chan chan updateResponse @@ -316,7 +315,6 @@ func (r *Repo) Start(ctx context.Context) error { l.Warn("could not restore previous repo content", zap.Error(err)) } else { l.Info("restored previous repo") - r.loaded.Store(true) } if r.poll { @@ -336,15 +334,9 @@ func (r *Repo) Start(ctx context.Context) error { zap.Float64("own_runtime", resp.Stats.OwnRuntime), zap.Float64("repo_runtime", resp.Stats.RepoRuntime), ) - } else { - r.loaded.Store(true) } } - if r.onStart != nil { - r.onStart() - } - return g.Wait() }