repair fixes
This commit is contained in:
@@ -18,8 +18,8 @@ import (
|
||||
)
|
||||
|
||||
type TorrentManager struct {
|
||||
TorrentMap *orderedmap.OrderedMap[string, *Torrent] // accessKey -> Torrent
|
||||
repairMap *orderedmap.OrderedMap[string, bool] // accessKey -> bool
|
||||
TorrentMap *orderedmap.OrderedMap[string, *Torrent] // accessKey -> Torrent
|
||||
repairMap *orderedmap.OrderedMap[string, time.Time] // accessKey -> time last repaired
|
||||
requiredVersion string
|
||||
rd *realdebrid.RealDebrid
|
||||
checksum string
|
||||
@@ -35,7 +35,7 @@ type TorrentManager struct {
|
||||
func NewTorrentManager(config config.ConfigInterface, rd *realdebrid.RealDebrid) *TorrentManager {
|
||||
t := &TorrentManager{
|
||||
TorrentMap: orderedmap.NewOrderedMap[string, *Torrent](),
|
||||
repairMap: orderedmap.NewOrderedMap[string, bool](),
|
||||
repairMap: orderedmap.NewOrderedMap[string, time.Time](),
|
||||
requiredVersion: "10.11.2023",
|
||||
rd: rd,
|
||||
config: config,
|
||||
@@ -514,7 +514,7 @@ func (t *TorrentManager) repairAll() {
|
||||
|
||||
// when getting info, we mark it for repair if it's missing some links
|
||||
if torrent.ForRepair {
|
||||
t.log.Infof("There were less links than was expected on %s; fixing...", torrent.AccessKey)
|
||||
t.log.Infof("Found torrent for repair %s", torrent.AccessKey)
|
||||
t.Repair(torrent.AccessKey)
|
||||
break // only repair the first one for repair and then move on
|
||||
}
|
||||
@@ -522,10 +522,12 @@ func (t *TorrentManager) repairAll() {
|
||||
}
|
||||
|
||||
func (t *TorrentManager) Repair(accessKey string) {
|
||||
if _, exists := t.repairMap.Get(accessKey); exists {
|
||||
return
|
||||
if lastRepair, ok := t.repairMap.Get(accessKey); ok {
|
||||
if time.Since(lastRepair) < time.Duration(24*time.Hour) { // magic number: 24 hrs
|
||||
return
|
||||
}
|
||||
}
|
||||
t.repairMap.Set(accessKey, true)
|
||||
t.repairMap.Set(accessKey, time.Now())
|
||||
|
||||
if !t.config.EnableRepair() {
|
||||
t.log.Warn("Repair is disabled; if you do not have other zurg instances running, you should enable repair")
|
||||
@@ -564,7 +566,7 @@ func (t *TorrentManager) Repair(accessKey string) {
|
||||
|
||||
// first solution: add the same selection, maybe it can be fixed by reinsertion?
|
||||
if t.reinsertTorrent(torrent, "") {
|
||||
t.log.Infof("Redownloaded torrent %s to repair it", torrent.AccessKey)
|
||||
t.log.Infof("Successfully downloaded torrent %s to repair it", torrent.AccessKey)
|
||||
return
|
||||
}
|
||||
// if all the selected files are missing but there are other streamable files
|
||||
@@ -633,7 +635,7 @@ func (t *TorrentManager) reinsertTorrent(torrent *Torrent, missingFiles string)
|
||||
}
|
||||
|
||||
if info.Status == "magnet_error" || info.Status == "error" || info.Status == "virus" || info.Status == "dead" {
|
||||
t.log.Warnf("Redownloaded torrent id=%s is in error state: %s", newTorrentID, info.Status)
|
||||
t.log.Warnf("The redownloaded torrent id=%s is in error state: %s", newTorrentID, info.Status)
|
||||
t.rd.DeleteTorrent(newTorrentID)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -54,14 +53,10 @@ func NewHTTPClient(token string, maxRetries int, c config.ConfigInterface) *HTTP
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
body2, _ := io.ReadAll(resp.Request.Body)
|
||||
log.Errorf("Received a %s %s from %s", resp.Status, string(body), resp.Request.URL)
|
||||
log.Errorf("request %s %s", string(body2), resp.Request.URL)
|
||||
if resp.StatusCode == 429 {
|
||||
return true
|
||||
}
|
||||
// no need to retry because the status code is 2XX
|
||||
// no need to retry
|
||||
return false
|
||||
},
|
||||
log: logutil.NewLogger().Named("http"),
|
||||
|
||||
@@ -153,7 +153,6 @@ func (rd *RealDebrid) GetTorrentInfo(id string) (*TorrentInfo, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rd.log.Debugf("Fetched info for torrent id=%s", response.ID)
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
@@ -178,7 +177,7 @@ func (rd *RealDebrid) SelectTorrentFiles(id string, files string) error {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
rd.log.Debugf("Selected files %s for torrent id=%s", len(strings.Split(files, ",")), id)
|
||||
rd.log.Debugf("Selected files %d for torrent id=%s", len(strings.Split(files, ",")), id)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,15 @@ import (
|
||||
)
|
||||
|
||||
func (rd *RealDebrid) UnrestrictUntilOk(link string) *UnrestrictResponse {
|
||||
unrestrictFn := func() (*UnrestrictResponse, error) {
|
||||
if link == "" {
|
||||
return nil
|
||||
}
|
||||
unrestrictFn := func(link string) (*UnrestrictResponse, error) {
|
||||
return rd.UnrestrictLink(link)
|
||||
}
|
||||
return retryUntilOk(unrestrictFn)
|
||||
return retryUntilOk(func() (*UnrestrictResponse, error) {
|
||||
return unrestrictFn(link)
|
||||
})
|
||||
}
|
||||
|
||||
func retryUntilOk[T any](fn func() (T, error)) T {
|
||||
|
||||
Reference in New Issue
Block a user