From eddaae3ccd93c0e57235107e747e444288e3272f Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Wed, 25 Feb 2026 10:39:56 -0500 Subject: [PATCH] Fix watch mode automatic startup on server launch Fixed a critical bug where watch mode failed to start automatically during container initialization, despite comments in app.go:79 claiming it would start "after 2-second delay." Root Cause: - StartWatchModeForAllLibraries() function existed but was never invoked - Comment in app.go claimed watch mode started automatically, but no startup code existed Changes: - Added "context" import to internal/router/router.go - Added goroutine in configureRouter() that: * Waits 2 seconds after server initialization * Calls StartWatchModeForAllLibraries() to activate monitoring * Logs startup status or errors This ensures watch mode begins scanning for new media files automatically when the container starts, rather than requiring manual intervention. Testing: Verified watch mode now activates automatically in container logs. --- internal/router/router.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/router/router.go b/internal/router/router.go index 6b85f7a..9475cd0 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -10,6 +10,7 @@ import ( "bookhoard/internal/sync" "bookhoard/templates" "bytes" + "context" "log" "net/http" "strings" @@ -234,6 +235,17 @@ func RegisterRoutes(cfg *Config) *handlers.Handler { // Start background tasks (queue processor and connection cleanup) scannerHandler.StartBackgroundTasks() + // Start watch mode for all libraries (after 2 second delay for DB) + go func() { + time.Sleep(2 * time.Second) + log.Println("Starting watch mode for all libraries...") + if err := scannerHandler.StartWatchModeForAllLibraries(context.Background()); err != nil { + log.Printf("Failed to start watch mode: %v", err) + } else { + log.Println("Watch mode started successfully") + } + }() + // Register progress routes with actual handler registerProgressRoutes(cfg, scannerHandler)