This commit is contained in:
Ben Sarmiento
2024-05-23 22:20:19 +02:00
parent 8636a0569d
commit beba993364
3 changed files with 78 additions and 36 deletions

View File

@@ -3,6 +3,7 @@ package torrent
import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"sync"
@@ -33,8 +34,6 @@ func (t *TorrentManager) refreshTorrents() []string {
freshIDs := mapset.NewSet[string]()
freshAccessKeys := mapset.NewSet[string]()
t.log.Infof("Getting info of %d torrents", len(instances))
for i := range instances {
wg.Add(1)
idx := i
@@ -156,7 +155,7 @@ func (t *TorrentManager) refreshTorrents() []string {
// StartRefreshJob periodically refreshes the torrents
func (t *TorrentManager) StartRefreshJob() {
go func() {
t.log.Info("Starting periodic refresh job")
t.log.Debug("Starting periodic refresh job")
refreshTicker := time.NewTicker(time.Duration(t.Config.GetRefreshEverySecs()) * time.Second)
defer refreshTicker.Stop()
@@ -417,3 +416,35 @@ func (t *TorrentManager) trash(torrentId string) {
t.log.Debugf("Trash: %s", torrentId)
t.trashBin.Add(torrentId)
}
func (t *TorrentManager) trashOnceCompleted(torrentId string) {
t.log.Debugf("Trash once completed: %s", torrentId)
t.repairBin.Add(torrentId)
}
func (t *TorrentManager) saveToBinFile() {
data := map[string]interface{}{
"trash_bin": t.trashBin.ToSlice(), // Assuming trashBin is a mapset.Set[string]
"repair_bin": t.repairBin.ToSlice(), // Assuming repairBin is a mapset.Set[string]
}
jsonData, err := json.Marshal(data)
if err != nil {
t.log.Errorf("Failed to marshal bin data: %v", err)
return
}
file, err := os.Create("trash_bin")
if err != nil {
t.log.Errorf("Failed to create trash_bin file: %v", err)
return
}
defer file.Close()
_, err = file.Write(jsonData)
if err != nil {
t.log.Errorf("Failed to write to trash_bin file: %v", err)
} else {
t.log.Debug("Successfully saved bins to file")
}
}