feat(scanner): restore auto-start functionality for scheduler and watch mode

Phase 1 of scanner restoration plan

Changes:
- cmd/server/main.go: Capture ebookHandler from router.RegisterRoutes
- cmd/server/main.go: Start scheduler in background goroutine
- cmd/server/main.go: Defer StopScheduler() for graceful shutdown
- cmd/server/main.go: Start watch mode for all libraries after 2-second delay
- internal/router/router.go: Return ebookHandler from RegisterRoutes

This restores critical functionality that was removed during router refactor:
- Auto-scanning now works again
- Watch mode starts automatically for all libraries
- Graceful shutdown properly stops scheduler

Fixes issue where scheduler and watch mode were not starting on server boot.
This commit is contained in:
2026-02-07 17:07:25 -05:00
parent 4bdd08602c
commit 2fc44e6d9c
2 changed files with 27 additions and 3 deletions
+19 -1
View File
@@ -148,7 +148,25 @@ func main() {
DeviceAuthMiddleware: deviceAuthMiddleware,
LoginTracker: loginAttemptTracker,
}
router.RegisterRoutes(routerConfig)
// Register all routes and get ebook handler
ebookHandler := router.RegisterRoutes(routerConfig)
// ========================================================================
// BACKGROUND SERVICES - Restore auto-start functionality
// ========================================================================
// Start scheduler for auto-scanning
go ebookHandler.StartScheduler()
defer ebookHandler.StopScheduler()
// Start watch mode for all libraries (background)
go func() {
time.Sleep(2 * time.Second) // Wait for server to be ready
if err := ebookHandler.StartWatchModeForAllLibraries(context.Background()); err != nil {
log.Printf("Warning: failed to start watch mode for libraries: %v", err)
}
}()
// Public library types endpoint (no authentication required)
e.GET("/api/libraries/types", libraryHandler.GetLibraryTypes)