Initialize empty stats store on bootstrap failure

If statsAllTime.Bootstrap fails, log the error but continue by initializing an empty stats map with a "_marker" entry set to today's date. This prevents repeated bootstrap attempts and allows the service to build stats incrementally going forward. The change acquires the stats mutex while updating the map and adds an informational log message.
This commit is contained in:
CanbiZ (MickLesk)
2026-02-17 13:21:10 +01:00
parent e332ca8dfa
commit 97f9f8d3cc
+8
View File
@@ -1861,6 +1861,14 @@ func main() {
ctx, cancel := context.WithTimeout(context.Background(), 900*time.Second)
if err := statsAllTime.Bootstrap(ctx, "ProxmoxVE"); err != nil {
log.Printf("[STATS:alltime] Bootstrap failed: %v", err)
log.Println("[STATS:alltime] Continuing with empty store - will build up incrementally")
// Initialize with today's date to start incremental updates from now on
today := time.Now().Format("2006-01-02")
statsAllTime.mu.Lock()
statsAllTime.stats = map[string]*CachedScriptStat{
"_marker": {LastDate: today}, // Marker to prevent re-bootstrap
}
statsAllTime.mu.Unlock()
}
cancel()
}