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

@@ -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
}