Support rebooting workers
This commit is contained in:
@@ -123,20 +123,27 @@ func (t *TorrentManager) refreshTorrents() []string {
|
||||
func (t *TorrentManager) StartRefreshJob() {
|
||||
_ = t.refreshPool.Submit(func() {
|
||||
t.log.Info("Starting periodic refresh job")
|
||||
refreshTicker := time.NewTicker(time.Duration(t.Config.GetRefreshEverySecs()) * time.Second)
|
||||
defer refreshTicker.Stop()
|
||||
|
||||
for {
|
||||
<-time.After(time.Duration(t.Config.GetRefreshEverySecs()) * time.Second)
|
||||
select {
|
||||
case <-refreshTicker.C:
|
||||
checksum := t.getCurrentState()
|
||||
if t.latestState.equal(checksum) {
|
||||
continue
|
||||
}
|
||||
t.SetNewLatestState(checksum)
|
||||
t.log.Infof("Detected changes! Refreshing %d torrents", checksum.TotalCount)
|
||||
|
||||
checksum := t.getCurrentState()
|
||||
if t.latestState.equal(checksum) {
|
||||
continue
|
||||
updatedPaths := t.refreshTorrents()
|
||||
t.log.Info("Finished refreshing torrents")
|
||||
|
||||
t.TriggerHookOnLibraryUpdate(updatedPaths)
|
||||
case <-t.RefreshKillSwitch:
|
||||
t.log.Info("Stopping periodic refresh job")
|
||||
return
|
||||
}
|
||||
t.SetNewLatestState(checksum)
|
||||
t.log.Infof("Detected changes! Refreshing %d torrents", checksum.TotalCount)
|
||||
|
||||
updatedPaths := t.refreshTorrents()
|
||||
t.log.Info("Finished refreshing torrents")
|
||||
|
||||
t.TriggerHookOnLibraryUpdate(updatedPaths)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user