Add job for monitoring bw limit status of tokens
This commit is contained in:
@@ -19,6 +19,7 @@ const (
|
||||
EXPIRED_LINK_TOLERANCE_HOURS = 24
|
||||
)
|
||||
|
||||
// StartRepairJob is a permanent job that runs every periodically to repair broken torrents
|
||||
func (t *TorrentManager) StartRepairJob() {
|
||||
if !t.Config.EnableRepair() {
|
||||
t.repairLog.Warn("Repair is disabled, skipping repair job")
|
||||
@@ -34,7 +35,6 @@ func (t *TorrentManager) StartRepairJob() {
|
||||
t.repairLog.Debug("Starting periodic repair job")
|
||||
repairTicker := time.NewTicker(time.Duration(t.Config.GetRepairEveryMins()) * time.Minute)
|
||||
defer repairTicker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-repairTicker.C:
|
||||
@@ -192,11 +192,12 @@ func (t *TorrentManager) repair(torrent *Torrent, wg *sync.WaitGroup) {
|
||||
bwLimitReached := false
|
||||
// check for other broken file
|
||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||
// we will only check for working files, we ignore broken and deleted files
|
||||
if bwLimitReached || !file.State.Is("ok_file") {
|
||||
return
|
||||
}
|
||||
_, err := t.UnrestrictFile(file)
|
||||
if utils.IsBWLimitExceeded(err) {
|
||||
if utils.AreAllTokensExpired(err) {
|
||||
bwLimitReached = true
|
||||
return
|
||||
}
|
||||
@@ -252,7 +253,7 @@ func (t *TorrentManager) repair(torrent *Torrent, wg *sync.WaitGroup) {
|
||||
info, err := t.redownloadTorrent(torrent, []string{}) // reinsert the whole torrent, passing empty selection
|
||||
if info != nil && info.Progress == 100 {
|
||||
err = t.checkIfBroken(info, brokenFiles)
|
||||
if utils.IsBWLimitExceeded(err) {
|
||||
if utils.AreAllTokensExpired(err) {
|
||||
t.repairLog.Warnf("Your account has reached the bandwidth limit, cannot continue repairing torrent %s", t.GetKey(torrent))
|
||||
return
|
||||
}
|
||||
@@ -332,14 +333,13 @@ func (t *TorrentManager) assignLinks(torrent *Torrent) bool {
|
||||
expiredCount := 0
|
||||
rarCount := 0
|
||||
unassignedCount := 0
|
||||
newUnassignedLinks := cmap.New[*realdebrid.Download]()
|
||||
var assignedLinks []string
|
||||
|
||||
bwLimitReached := false
|
||||
torrent.UnassignedLinks.Clone().Each(func(link string) bool {
|
||||
// unrestrict each unassigned link that was filled out during torrent init
|
||||
unrestrict, err := t.rd.UnrestrictAndVerify(link)
|
||||
if utils.IsBWLimitExceeded(err) {
|
||||
if utils.AreAllTokensExpired(err) {
|
||||
bwLimitReached = true
|
||||
return true
|
||||
}
|
||||
@@ -377,7 +377,18 @@ func (t *TorrentManager) assignLinks(torrent *Torrent) bool {
|
||||
// it's possible that it is already repaired
|
||||
t.repairLog.Warnf("Cannot assign %s to any file in torrent %s", unrestrict.Filename, t.GetKey(torrent))
|
||||
}
|
||||
newUnassignedLinks.Set(link, unrestrict)
|
||||
|
||||
torrent.SelectedFiles.Set(unrestrict.Filename, &File{
|
||||
File: realdebrid.File{
|
||||
ID: 0,
|
||||
Path: unrestrict.Filename,
|
||||
Bytes: unrestrict.Filesize,
|
||||
Selected: 0,
|
||||
},
|
||||
Ended: torrent.Added,
|
||||
Link: unrestrict.Link,
|
||||
State: NewFileState("ok_file"),
|
||||
})
|
||||
}
|
||||
|
||||
processedCount := assignedCount + unassignedCount + expiredCount
|
||||
@@ -416,20 +427,6 @@ func (t *TorrentManager) assignLinks(torrent *Torrent) bool {
|
||||
return false // end repair
|
||||
}
|
||||
|
||||
newUnassignedLinks.IterCb(func(_ string, unassigned *realdebrid.Download) {
|
||||
torrent.SelectedFiles.Set(unassigned.Filename, &File{
|
||||
File: realdebrid.File{
|
||||
ID: 0,
|
||||
Path: unassigned.Filename,
|
||||
Bytes: unassigned.Filesize,
|
||||
Selected: 0,
|
||||
},
|
||||
Ended: torrent.Added,
|
||||
Link: unassigned.Link,
|
||||
State: NewFileState("ok_file"),
|
||||
})
|
||||
})
|
||||
|
||||
if action == "extract" {
|
||||
videoFiles := []string{}
|
||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||
|
||||
Reference in New Issue
Block a user