From 182c0b5d5e5eb8901fd66bfcf043494a7b9652ec Mon Sep 17 00:00:00 2001 From: Deluan Date: Wed, 22 Jan 2020 08:48:02 -0500 Subject: [PATCH] Add configuration for scan interval. Default 5 mins --- conf/configuration.go | 1 + server/server.go | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/conf/configuration.go b/conf/configuration.go index e885a01f7..3497152ab 100644 --- a/conf/configuration.go +++ b/conf/configuration.go @@ -21,6 +21,7 @@ type sonic struct { ProbeCommand string `default:"ffmpeg %s -f ffmetadata"` PlsIgnoreFolders bool `default:"true"` PlsIgnoredPatterns string `default:"^iCloud;\\~"` + ScanInterval string `default:"5m"` // DevFlags. These are used to enable/disable debugging and incomplete features DevDisableAuthentication bool `default:"false"` diff --git a/server/server.go b/server/server.go index 990e10770..55c4f2b7d 100644 --- a/server/server.go +++ b/server/server.go @@ -68,15 +68,21 @@ func (a *Server) initRoutes() { } func (a *Server) initScanner() { + interval, err := time.ParseDuration(conf.Sonic.ScanInterval) + if err != nil { + log.Error("Invalid interval specification. Using default of 5m", "conf", conf.Sonic.ScanInterval, err) + interval = 5 * time.Minute + } else { + log.Info("Starting scanner", "interval", interval.String()) + } go func() { + time.Sleep(2 * time.Second) for { - select { - case <-time.After(5 * time.Second): - err := a.Scanner.RescanAll(false) - if err != nil { - log.Error("Error scanning media folder", "folder", conf.Sonic.MusicFolder, err) - } + err := a.Scanner.RescanAll(false) + if err != nil { + log.Error("Error scanning media folder", "folder", conf.Sonic.MusicFolder, err) } + time.Sleep(interval) } }() }