mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-09-23 03:33:53 +00:00
Improve update procedure tracking
This commit is contained in:
+12
-2
@@ -52,6 +52,7 @@ type Router struct {
|
||||
wsHub *websocket.Hub
|
||||
reloadFunc func() error
|
||||
updateManager *updates.Manager
|
||||
updateHistory *updates.UpdateHistory
|
||||
exportLimiter *RateLimiter
|
||||
persistence *config.ConfigPersistence
|
||||
oidcMu sync.Mutex
|
||||
@@ -101,18 +102,27 @@ func NewRouter(cfg *config.Config, monitor *monitoring.Monitor, wsHub *websocket
|
||||
InitSessionStore(cfg.DataPath)
|
||||
InitCSRFStore(cfg.DataPath)
|
||||
|
||||
updateHistory, err := updates.NewUpdateHistory(cfg.DataPath)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to initialize update history")
|
||||
}
|
||||
|
||||
projectRoot, err := os.Getwd()
|
||||
if err != nil {
|
||||
projectRoot = "."
|
||||
}
|
||||
|
||||
updateManager := updates.NewManager(cfg)
|
||||
updateManager.SetHistory(updateHistory)
|
||||
|
||||
r := &Router{
|
||||
mux: http.NewServeMux(),
|
||||
config: cfg,
|
||||
monitor: monitor,
|
||||
wsHub: wsHub,
|
||||
reloadFunc: reloadFunc,
|
||||
updateManager: updates.NewManager(cfg),
|
||||
updateManager: updateManager,
|
||||
updateHistory: updateHistory,
|
||||
exportLimiter: NewRateLimiter(5, 1*time.Minute), // 5 attempts per minute
|
||||
persistence: config.NewConfigPersistence(cfg.DataPath),
|
||||
projectRoot: projectRoot,
|
||||
@@ -160,7 +170,7 @@ func (r *Router) setupRoutes() {
|
||||
guestMetadataHandler := NewGuestMetadataHandler(r.config.DataPath)
|
||||
dockerMetadataHandler := NewDockerMetadataHandler(r.config.DataPath)
|
||||
r.configHandlers = NewConfigHandlers(r.config, r.monitor, r.reloadFunc, r.wsHub, guestMetadataHandler, r.reloadSystemSettings)
|
||||
updateHandlers := NewUpdateHandlers(r.updateManager, r.config.DataPath)
|
||||
updateHandlers := NewUpdateHandlers(r.updateManager, r.updateHistory)
|
||||
r.dockerAgentHandlers = NewDockerAgentHandlers(r.monitor, r.wsHub)
|
||||
r.hostAgentHandlers = NewHostAgentHandlers(r.monitor, r.wsHub)
|
||||
r.temperatureProxyHandlers = NewTemperatureProxyHandlers(r.persistence)
|
||||
|
||||
+8
-10
@@ -25,15 +25,7 @@ type UpdateHandlers struct {
|
||||
}
|
||||
|
||||
// NewUpdateHandlers creates new update handlers
|
||||
func NewUpdateHandlers(manager *updates.Manager, dataDir string) *UpdateHandlers {
|
||||
// Initialize update history using configured data directory
|
||||
// Empty string defaults to /var/lib/pulse for backward compatibility
|
||||
history, err := updates.NewUpdateHistory(dataDir)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to initialize update history")
|
||||
// Continue without history - handlers will check for nil
|
||||
}
|
||||
|
||||
func NewUpdateHandlers(manager *updates.Manager, history *updates.UpdateHistory) *UpdateHandlers {
|
||||
// Initialize updater registry
|
||||
registry := updates.NewUpdaterRegistry()
|
||||
|
||||
@@ -108,7 +100,13 @@ func (h *UpdateHandlers) HandleApplyUpdate(w http.ResponseWriter, r *http.Reques
|
||||
// Start update in background with a new context (not request context which gets cancelled)
|
||||
go func() {
|
||||
ctx := context.Background()
|
||||
if err := h.manager.ApplyUpdate(ctx, req.DownloadURL); err != nil {
|
||||
applyReq := updates.ApplyUpdateRequest{
|
||||
DownloadURL: req.DownloadURL,
|
||||
Channel: r.URL.Query().Get("channel"),
|
||||
InitiatedBy: updates.InitiatedByUser,
|
||||
InitiatedVia: updates.InitiatedViaUI,
|
||||
}
|
||||
if err := h.manager.ApplyUpdate(ctx, applyReq); err != nil {
|
||||
log.Error().Err(err).Msg("Failed to apply update")
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user