mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-05 13:37:38 +03:00
Add trigger scan when receiving SIGUSR1 signal
This commit is contained in:
parent
e83a0b23a3
commit
1e539f4e54
1 changed files with 14 additions and 1 deletions
|
@ -4,8 +4,11 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/navidrome/navidrome/core"
|
"github.com/navidrome/navidrome/core"
|
||||||
|
@ -39,7 +42,10 @@ type FolderScanner interface {
|
||||||
Scan(ctx context.Context, lastModifiedSince time.Time, progress chan uint32) error
|
Scan(ctx context.Context, lastModifiedSince time.Time, progress chan uint32) error
|
||||||
}
|
}
|
||||||
|
|
||||||
var isScanning utils.AtomicBool
|
var (
|
||||||
|
isScanning utils.AtomicBool
|
||||||
|
sigChan = make(chan os.Signal, 1)
|
||||||
|
)
|
||||||
|
|
||||||
type scanner struct {
|
type scanner struct {
|
||||||
folders map[string]FolderScanner
|
folders map[string]FolderScanner
|
||||||
|
@ -68,6 +74,10 @@ func New(ds model.DataStore, cacheWarmer core.CacheWarmer, broker events.Broker)
|
||||||
lock: &sync.RWMutex{},
|
lock: &sync.RWMutex{},
|
||||||
scan: make(chan bool),
|
scan: make(chan bool),
|
||||||
}
|
}
|
||||||
|
signals := []os.Signal{
|
||||||
|
syscall.SIGUSR1,
|
||||||
|
}
|
||||||
|
signal.Notify(sigChan, signals...)
|
||||||
s.loadFolders()
|
s.loadFolders()
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -83,6 +93,9 @@ func (s *scanner) Run(ctx context.Context, interval time.Duration) {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
continue
|
continue
|
||||||
|
case sig := <-sigChan:
|
||||||
|
log.Info(ctx, "Received signal, triggering a new scan", "signal", sig)
|
||||||
|
continue
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue