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.
This commit is contained in:
2026-02-25 10:39:56 -05:00
parent e8effeb666
commit eddaae3ccd
+12
View File
@@ -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)