mirror of
https://github.com/foomo/contentserver.git
synced 2025-10-16 12:25:44 +00:00
fix: update persisted json after updating the repo using the poll routine
This commit is contained in:
parent
74d2ff75f5
commit
fe1d9de6f1
@ -75,10 +75,6 @@ func (h *HTTP) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
route := Route(strings.TrimPrefix(r.URL.Path, h.basePath+"/"))
|
||||
if route == RouteGetRepo {
|
||||
resp := h.repo.Update()
|
||||
if !resp.Success {
|
||||
h.l.Warn("repo update failed — serving previously cached data", zap.String("reason", resp.ErrorMessage))
|
||||
}
|
||||
h.repo.WriteRepoBytes(w)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
return
|
||||
|
||||
@ -305,6 +305,15 @@ func (r *Repo) update(ctx context.Context) (repoRuntime int64, err error) {
|
||||
if r.poll {
|
||||
r.pollVersion = repoURL
|
||||
}
|
||||
|
||||
// Persist the JSON buffer after successful update
|
||||
if err := r.history.Add(r.JSONBufferBytes()); err != nil {
|
||||
r.l.Error("Failed to persist repo after update", zap.Error(err))
|
||||
metrics.HistoryPersistFailedCounter.WithLabelValues().Inc()
|
||||
} else {
|
||||
r.l.Info("Successfully persisted repo after update")
|
||||
}
|
||||
|
||||
return repoRuntime, nil
|
||||
}
|
||||
|
||||
|
||||
@ -285,6 +285,8 @@ func (r *Repo) Update() (updateResponse *responses.Update) {
|
||||
if historyErr != nil {
|
||||
r.l.Error("Could not persist current repo in history", zap.Error(historyErr))
|
||||
metrics.HistoryPersistFailedCounter.WithLabelValues().Inc()
|
||||
} else {
|
||||
r.l.Info("Successfully persisted current repo to history")
|
||||
}
|
||||
// add some stats
|
||||
for _, dimension := range r.Directory() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user