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:
+19
-1
@@ -148,7 +148,25 @@ func main() {
|
|||||||
DeviceAuthMiddleware: deviceAuthMiddleware,
|
DeviceAuthMiddleware: deviceAuthMiddleware,
|
||||||
LoginTracker: loginAttemptTracker,
|
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)
|
// Public library types endpoint (no authentication required)
|
||||||
e.GET("/api/libraries/types", libraryHandler.GetLibraryTypes)
|
e.GET("/api/libraries/types", libraryHandler.GetLibraryTypes)
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ func createJWTMiddleware(cfg *Config) echo.MiddlewareFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RegisterRoutes registers all application routes
|
// RegisterRoutes registers all application routes
|
||||||
func RegisterRoutes(cfg *Config) {
|
func RegisterRoutes(cfg *Config) *handlers.Handler {
|
||||||
e := cfg.Echo
|
e := cfg.Echo
|
||||||
|
|
||||||
// Set up validator
|
// Set up validator
|
||||||
@@ -111,7 +111,7 @@ func RegisterRoutes(cfg *Config) {
|
|||||||
// Register core application routes (collections, devices, media, etc.) - ONCE
|
// Register core application routes (collections, devices, media, etc.) - ONCE
|
||||||
jwtMiddleware := createJWTMiddleware(cfg)
|
jwtMiddleware := createJWTMiddleware(cfg)
|
||||||
protected := e.Group("/api", jwtMiddleware)
|
protected := e.Group("/api", jwtMiddleware)
|
||||||
handlers.SetupRoutes(protected, cfg.Queries, cfg.ConnManager)
|
ebookHandler := handlers.SetupRoutes(protected, cfg.Queries, cfg.ConnManager)
|
||||||
|
|
||||||
// Register route groups
|
// Register route groups
|
||||||
registerAuthRoutes(cfg, rateLimitMiddleware)
|
registerAuthRoutes(cfg, rateLimitMiddleware)
|
||||||
@@ -126,4 +126,10 @@ func RegisterRoutes(cfg *Config) {
|
|||||||
registerWebSocketRoutes(cfg)
|
registerWebSocketRoutes(cfg)
|
||||||
registerFrontendRoutes(cfg)
|
registerFrontendRoutes(cfg)
|
||||||
registerDocumentationRoutes(cfg)
|
registerDocumentationRoutes(cfg)
|
||||||
|
|
||||||
|
// Register scanner routes (admin only)
|
||||||
|
admin := protected.Group("", handlers.AdminMiddleware)
|
||||||
|
registerScannerRoutes(admin, ebookHandler)
|
||||||
|
|
||||||
|
return ebookHandler
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user