refactor: mark loaded

This commit is contained in:
Kevin Franklin Kim 2024-03-22 16:26:34 +01:00
parent 5e7798a53f
commit ae481c5278
No known key found for this signature in database
2 changed files with 18 additions and 18 deletions

View File

@ -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()
}

View File

@ -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()
}