Files
bookhoard/internal/handlers/commonhandlers.go
T
john-okeefe 286d0b5e06 feat(scanner): convert scan poll interval from minutes to seconds
- Rename SCAN_POLL_INTERVAL_MINUTES to SCAN_POLL_INTERVAL_SECONDS in config
- Update MediaScanner to accept interval in seconds instead of minutes
- Adjust default polling interval from 3 minutes to 30 seconds for faster response
- Add debug logging for fsnotify events to aid troubleshooting file watching

This change improves media file detection responsiveness by reducing the
polling interval from minutes to seconds, while maintaining the file
watcher as the primary detection mechanism.
2026-02-28 01:59:35 -05:00

74 lines
2.2 KiB
Go

package handlers
import (
"bookhoard/internal/config"
"bookhoard/internal/database"
"bookhoard/internal/services"
wsync "bookhoard/internal/sync"
"context"
"sync"
"time"
"github.com/labstack/echo/v4"
)
type Handler struct {
db *database.Queries
scanner *services.MediaScanner
worker *services.Worker
scheduler *services.Scheduler
queueProcessor *wsync.SyncQueueProcessor
queueCtx context.Context
queueCancel context.CancelFunc
ctx context.Context
cancel context.CancelFunc
mu sync.Mutex
watchModeCtx context.Context
watchModeCancel context.CancelFunc
watchingLibraries map[string]bool
connManager *wsync.ConnectionManager
cleanupTaskCancel context.CancelFunc
config *config.Config
}
func NewHandler(db *database.Queries, connManager *wsync.ConnectionManager, queueProcessor *wsync.SyncQueueProcessor, cfg *config.Config) *Handler {
ctx, cancel := context.WithCancel(context.Background())
worker := services.NewWorker(3)
scheduler := services.NewScheduler(worker, db)
queueCtx, queueCancel := context.WithCancel(context.Background())
watchCtx, watchCancel := context.WithCancel(context.Background())
return &Handler{
db: db,
scanner: services.NewMediaScanner(db, cfg.ScanPollIntervalSeconds),
worker: worker,
scheduler: scheduler,
queueProcessor: queueProcessor,
queueCtx: queueCtx,
queueCancel: queueCancel,
ctx: ctx,
cancel: cancel,
watchModeCtx: watchCtx,
watchModeCancel: watchCancel,
watchingLibraries: make(map[string]bool),
connManager: connManager,
}
}
// parseDate parses a date string in YYYY-MM-DD format
func parseDate(dateStr string) time.Time {
if dateStr == "" {
return time.Time{}
}
if t, err := time.Parse("2006-01-02", dateStr); err == nil {
return t
}
return time.Time{}
}
func SetupRoutes(g *echo.Group, db *database.Queries, connManager *wsync.ConnectionManager, queueProcessor *wsync.SyncQueueProcessor, cfg *config.Config) *Handler {
return NewHandler(db, connManager, queueProcessor, cfg)
}