Add repair all trigger

This commit is contained in:
Ben Adrian Sarmiento
2024-06-14 14:25:51 +02:00
parent 92aaab875c
commit b1427c2d63
6 changed files with 52 additions and 32 deletions

View File

@@ -134,7 +134,7 @@ func (t *TorrentManager) binOnceDoneErrorCheck(torrentId, status string) bool {
if status == "downloading" || status == "downloaded" || status == "uploading" || status == "queued" || status == "compressing" || status == "waiting_files_selection" {
return false
}
t.repairLog.Errorf("Bin: error status=%s, checking if %s should be deleted", status, torrentId)
t.repairLog.Infof("Bin: error status=%s, checking if %s should be deleted", status, torrentId)
return t.binOnceDone(torrentId, true)
}

View File

@@ -39,11 +39,12 @@ type TorrentManager struct {
RootNode *fs.FileNode
RefreshKillSwitch chan struct{}
RepairKillSwitch chan struct{}
RemountTrigger chan struct{}
DumpTrigger chan struct{}
AnalyzeTrigger chan struct{}
RefreshWorkerKillSwitch chan struct{}
RepairWorkerKillSwitch chan struct{}
RemountTrigger chan struct{}
RepairAllTrigger chan struct{}
DumpTrigger chan struct{}
AnalyzeTrigger chan struct{}
latestState *LibraryState
inProgressHashes mapset.Set[string]
@@ -76,11 +77,12 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
RootNode: fs.NewFileNode("root", true),
RefreshKillSwitch: make(chan struct{}, 1),
RepairKillSwitch: make(chan struct{}, 1),
RemountTrigger: make(chan struct{}, 1),
DumpTrigger: make(chan struct{}, 1),
AnalyzeTrigger: make(chan struct{}, 1),
RefreshWorkerKillSwitch: make(chan struct{}, 1),
RepairWorkerKillSwitch: make(chan struct{}, 1),
RemountTrigger: make(chan struct{}, 1),
// RepairAllTrigger: make(chan struct{}, 1), // initialized in repair.go
DumpTrigger: make(chan struct{}, 1),
AnalyzeTrigger: make(chan struct{}, 1),
latestState: &LibraryState{log: log},
}

View File

@@ -152,7 +152,7 @@ func (t *TorrentManager) StartRefreshJob() {
t.refreshTorrents(false)
t.log.Info("Finished refreshing torrents")
case <-t.RefreshKillSwitch:
case <-t.RefreshWorkerKillSwitch:
t.log.Info("Stopping periodic refresh job")
return
}

View File

@@ -26,6 +26,7 @@ func (t *TorrentManager) StartRepairJob() {
}
t.repairTrigger = make(chan *Torrent)
t.repairQueue = mapset.NewSet[*Torrent]()
t.RepairAllTrigger = make(chan struct{})
// there is 1 repair worker, with max 1 blocking task
t.workerPool.Submit(func() {
t.repairLog.Debug("Starting periodic repair job")
@@ -36,10 +37,12 @@ func (t *TorrentManager) StartRepairJob() {
select {
case <-repairTicker.C:
t.invokeRepair(nil)
case <-t.RepairAllTrigger:
t.invokeRepair(nil)
case torrent := <-t.repairTrigger:
// On-demand trigger with a specific torrent
t.invokeRepair(torrent)
case <-t.RepairKillSwitch:
case <-t.RepairWorkerKillSwitch:
t.repairLog.Info("Stopping periodic repair job")
return
}
@@ -76,15 +79,19 @@ func (t *TorrentManager) invokeRepair(torrent *Torrent) {
// TriggerRepair allows an on-demand repair to be initiated.
func (t *TorrentManager) TriggerRepair(torrent *Torrent) {
if !t.Config.EnableRepair() {
if torrent != nil {
t.repairLog.Warnf("Repair is disabled, skipping repair for torrent %s", t.GetKey(torrent))
} else {
t.repairLog.Warn("Repair is disabled, skipping repair")
}
return
}
if torrent != nil {
if err := torrent.State.Event(context.Background(), "break_torrent"); err != nil {
// t.repairLog.Errorf("Failed to mark torrent %s as broken: %v", t.GetKey(torrent), err)
return
}
if !t.Config.EnableRepair() {
t.repairLog.Warnf("Repair is disabled, skipping repair for torrent %s", t.GetKey(torrent))
return
}
}
t.repairTrigger <- torrent
}