-
-
Notifications
You must be signed in to change notification settings - Fork 817
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
54 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build windows || plan9 | ||
|
||
package cmd | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// Windows and Plan9 don't support SIGUSR1, so we don't need to start a signaler | ||
func startSignaler(ctx context.Context) func() error { | ||
return func() error { | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//go:build !windows && !plan9 | ||
|
||
package cmd | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/navidrome/navidrome/log" | ||
) | ||
|
||
const triggerScanSignal = syscall.SIGUSR1 | ||
|
||
func startSignaler(ctx context.Context) func() error { | ||
log.Info(ctx, "Starting signaler") | ||
scanner := GetScanner() | ||
|
||
return func() error { | ||
var sigChan = make(chan os.Signal, 1) | ||
signal.Notify(sigChan, triggerScanSignal) | ||
|
||
for { | ||
select { | ||
case sig := <-sigChan: | ||
log.Info(ctx, "Received signal, triggering a new scan", "signal", sig) | ||
start := time.Now() | ||
err := scanner.RescanAll(ctx, false) | ||
if err != nil { | ||
log.Error(ctx, "Error scanning", err) | ||
} | ||
log.Info(ctx, "Triggered scan complete", "elapsed", time.Since(start).Round(100*time.Millisecond)) | ||
case <-ctx.Done(): | ||
return nil | ||
} | ||
} | ||
} | ||
} |