Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

fix: Populate resources on-demand when /api/resources is called

rcourtmanf7735cca62aa
diff --git a/internal/api/resource_handlers.go b/internal/api/resource_handlers.go
index a6ce5a2667..c1cad68602 100644
--- a/internal/api/resource_handlers.go
+++ b/internal/api/resource_handlers.go
@@ -9,9 +9,15 @@ import (
"github.com/rcourtman/pulse-go-rewrite/internal/resources"
)
+// StateProvider allows ResourceHandlers to fetch current state on demand.
+type StateProvider interface {
+ GetState() models.StateSnapshot
+}
+
// ResourceHandlers provides HTTP handlers for the unified resource API.
type ResourceHandlers struct {
- store *resources.Store
+ store *resources.Store
+ stateProvider StateProvider
}
// NewResourceHandlers creates resource handlers with a new store.
@@ -21,6 +27,11 @@ func NewResourceHandlers() *ResourceHandlers {
}
}
+// SetStateProvider sets the state provider for on-demand resource population.
+func (h *ResourceHandlers) SetStateProvider(provider StateProvider) {
+ h.stateProvider = provider
+}
+
// Store returns the underlying resource store for populating from the monitor.
func (h *ResourceHandlers) Store() *resources.Store {
return h.store
@@ -41,6 +52,12 @@ func (h *ResourceHandlers) HandleGetResources(w http.ResponseWriter, r *http.Req
return
}
+ // Populate from current state if we have a state provider
+ // This ensures fresh data even if the store hasn't been populated yet
+ if h.stateProvider != nil {
+ h.PopulateFromSnapshot(h.stateProvider.GetState())
+ }
+
query := h.store.Query()
// Parse type filter
diff --git a/internal/api/router.go b/internal/api/router.go
index e7f0cc373e..cf0e6fb0e2 100644
--- a/internal/api/router.go
+++ b/internal/api/router.go
@@ -1279,6 +1279,8 @@ func (r *Router) SetMonitor(m *monitoring.Monitor) {
// Inject resource store for polling optimization
if r.resourceHandlers != nil {
m.SetResourceStore(r.resourceHandlers.Store())
+ // Also set state provider for on-demand resource population
+ r.resourceHandlers.SetStateProvider(m)
}
}
}