Fix repair condition
This commit is contained in:
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@@ -5,7 +5,7 @@ on:
|
||||
tags:
|
||||
- '*'
|
||||
schedule:
|
||||
- cron: '0 10 * * *'
|
||||
- cron: '20 11 * * *'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
continue-on-error: false
|
||||
run: |
|
||||
# 3AM CET
|
||||
since="$(date -d 'yesterday' +%Y-%m-%d) 10:00:00"
|
||||
since="$(date -d 'yesterday' +%Y-%m-%d) 11:20:00"
|
||||
count=$(git rev-list --count --since="$since" --until=now HEAD)
|
||||
if [ "$count" -gt 0 ]; then
|
||||
echo "new_commits=true" >> $GITHUB_OUTPUT
|
||||
|
||||
2
.github/workflows/build_docker.yml
vendored
2
.github/workflows/build_docker.yml
vendored
@@ -5,7 +5,7 @@ on:
|
||||
tags:
|
||||
- '*'
|
||||
schedule:
|
||||
- cron: '0 10 * * *'
|
||||
- cron: '20 11 * * *'
|
||||
|
||||
jobs:
|
||||
build-and-push-image:
|
||||
|
||||
@@ -270,7 +270,7 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
|
||||
<td>%v</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>IDs to be deleted once download completes</td>
|
||||
<td>IDs to be deleted</td>
|
||||
<td colspan="2">%v</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -288,6 +288,9 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
|
||||
<form method="post" action="/torrents/repair">
|
||||
<input type="submit" value="Repair torrents" /> Trigger repair of all torrents
|
||||
</form>
|
||||
<form method="post" action="/torrents/reset-repair-state">
|
||||
<input type="submit" value="Reset repair state" /> Reset repair state of all torrents so they can be repaired again
|
||||
</form>
|
||||
</td>
|
||||
<tr>
|
||||
<td>Debug</td>
|
||||
@@ -367,58 +370,6 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
|
||||
fmt.Fprint(resp, out)
|
||||
}
|
||||
|
||||
func (zr *Handlers) handleRebootWorkerPool(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Set("Refresh", "2; url=/")
|
||||
zr.workerPool.Release()
|
||||
zr.workerPool.Reboot()
|
||||
zr.log.Infof("Rebooted worker pool")
|
||||
fmt.Fprint(resp, "Rebooting worker pool...")
|
||||
}
|
||||
|
||||
func (zr *Handlers) handleRebootRefreshWorker(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Set("Refresh", "2; url=/")
|
||||
zr.torMgr.RefreshWorkerKillSwitch <- struct{}{}
|
||||
zr.torMgr.StartRefreshJob()
|
||||
zr.log.Infof("Rebooted refresh worker")
|
||||
fmt.Fprint(resp, "Rebooting refresh worker...")
|
||||
}
|
||||
|
||||
func (zr *Handlers) handleRebootRepairWorker(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Set("Refresh", "2; url=/")
|
||||
zr.torMgr.RepairWorkerKillSwitch <- struct{}{}
|
||||
zr.torMgr.StartRepairJob()
|
||||
zr.log.Infof("Rebooted repair worker")
|
||||
fmt.Fprint(resp, "Rebooting repair worker...")
|
||||
}
|
||||
|
||||
func (zr *Handlers) handleRemountDownloads(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Set("Refresh", "2; url=/")
|
||||
zr.torMgr.RemountTrigger <- struct{}{}
|
||||
zr.log.Infof("Triggered remount of downloads")
|
||||
fmt.Fprint(resp, "Remounting downloads...")
|
||||
}
|
||||
|
||||
func (zr *Handlers) handleDumpTorrents(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Set("Refresh", "2; url=/")
|
||||
zr.torMgr.DumpTrigger <- struct{}{}
|
||||
zr.log.Infof("Triggered dump of torrents")
|
||||
fmt.Fprint(resp, "Dumping torrents...")
|
||||
}
|
||||
|
||||
func (zr *Handlers) handleAnalyzeTorrents(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Set("Refresh", "2; url=/")
|
||||
zr.torMgr.AnalyzeTrigger <- struct{}{}
|
||||
zr.log.Infof("Triggered media analysis of torrents")
|
||||
fmt.Fprint(resp, "Analyzing all torrents...")
|
||||
}
|
||||
|
||||
func (zr *Handlers) handleTriggerRepairAll(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Set("Refresh", "2; url=/")
|
||||
zr.torMgr.EnqueueForRepair(nil)
|
||||
zr.log.Infof("Triggered repair of all torrents")
|
||||
fmt.Fprint(resp, "Repairing all torrents...")
|
||||
}
|
||||
|
||||
func bToMb(b uint64) uint64 {
|
||||
return b / 1024 / 1024
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ func AttachHandlers(router *chi.Mux, downloader *universal.Downloader, torMgr *t
|
||||
router.Post("/torrents/dump", hs.handleDumpTorrents)
|
||||
router.Post("/torrents/analyze", hs.handleAnalyzeTorrents)
|
||||
router.Post("/torrents/repair", hs.handleTriggerRepairAll)
|
||||
router.Post("/torrents/reset-repair-state", hs.handleResetRepairState)
|
||||
// version
|
||||
router.Get(fmt.Sprintf("/{mountType}/%s", version.FILE), hs.handleVersionFile)
|
||||
router.Head(fmt.Sprintf("/{mountType}/%s", version.FILE), hs.handleCheckVersionFile)
|
||||
|
||||
65
internal/handlers/util.go
Normal file
65
internal/handlers/util.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (zr *Handlers) handleRebootWorkerPool(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Set("Refresh", "2; url=/")
|
||||
zr.log.Infof("Rebooting worker pool")
|
||||
zr.workerPool.Release()
|
||||
zr.workerPool.Reboot()
|
||||
fmt.Fprint(resp, "Worker pool rebooted")
|
||||
}
|
||||
|
||||
func (zr *Handlers) handleRebootRefreshWorker(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Set("Refresh", "2; url=/")
|
||||
zr.log.Infof("Rebooting refresh worker")
|
||||
zr.torMgr.RefreshWorkerKillSwitch <- struct{}{}
|
||||
zr.torMgr.StartRefreshJob()
|
||||
fmt.Fprint(resp, "Refresh worker rebooted")
|
||||
}
|
||||
|
||||
func (zr *Handlers) handleRebootRepairWorker(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Set("Refresh", "2; url=/")
|
||||
zr.log.Infof("Rebooting repair worker")
|
||||
zr.torMgr.RepairWorkerKillSwitch <- struct{}{}
|
||||
zr.torMgr.StartRepairJob()
|
||||
fmt.Fprint(resp, "Repair worker rebooted")
|
||||
}
|
||||
|
||||
func (zr *Handlers) handleRemountDownloads(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Set("Refresh", "2; url=/")
|
||||
zr.log.Infof("Triggering remount of downloads")
|
||||
zr.torMgr.RemountTrigger <- struct{}{}
|
||||
fmt.Fprint(resp, "Triggered remount of downloads")
|
||||
}
|
||||
|
||||
func (zr *Handlers) handleDumpTorrents(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Set("Refresh", "2; url=/")
|
||||
zr.log.Infof("Triggering dump of torrents")
|
||||
zr.torMgr.DumpTrigger <- struct{}{}
|
||||
fmt.Fprint(resp, "Triggered dump of torrents")
|
||||
}
|
||||
|
||||
func (zr *Handlers) handleAnalyzeTorrents(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Set("Refresh", "2; url=/")
|
||||
zr.log.Infof("Triggered analysis of all torrents")
|
||||
zr.torMgr.AnalyzeTrigger <- struct{}{}
|
||||
fmt.Fprint(resp, "Triggered analysis of all torrents")
|
||||
}
|
||||
|
||||
func (zr *Handlers) handleTriggerRepairAll(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Set("Refresh", "2; url=/")
|
||||
zr.log.Infof("Triggering repair of all torrents")
|
||||
zr.torMgr.EnqueueForRepair(nil)
|
||||
fmt.Fprint(resp, "Triggered repair of all torrents")
|
||||
}
|
||||
|
||||
func (zr *Handlers) handleResetRepairState(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Set("Refresh", "2; url=/")
|
||||
zr.log.Infof("Resetting repair state of all torrents")
|
||||
zr.torMgr.ResetRepairState()
|
||||
fmt.Fprint(resp, "Repair state of all torrents has been reset")
|
||||
}
|
||||
@@ -152,7 +152,6 @@ func (t *TorrentManager) StartRefreshJob() {
|
||||
continue
|
||||
}
|
||||
t.setNewLatestState(checksum)
|
||||
|
||||
t.refreshTorrents(false)
|
||||
t.log.Info("Finished refreshing torrents")
|
||||
case <-t.RefreshWorkerKillSwitch:
|
||||
|
||||
@@ -124,7 +124,7 @@ func (t *TorrentManager) executeRepairJob(torrent *Torrent) {
|
||||
t.workerPool.Submit(func() {
|
||||
defer wg.Done()
|
||||
canExtract := t.Config.GetRarAction() == "extract" && strings.Contains(torrent.UnrepairableReason, "rar")
|
||||
if !canExtract || torrent.UnrepairableReason != "" {
|
||||
if torrent.UnrepairableReason != "" && !canExtract {
|
||||
return
|
||||
}
|
||||
// check 1: for broken files
|
||||
@@ -640,3 +640,17 @@ func (t *TorrentManager) isStillBroken(info *realdebrid.TorrentInfo, brokenFiles
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *TorrentManager) ResetRepairState() {
|
||||
if !t.Config.EnableRepair() {
|
||||
return
|
||||
}
|
||||
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
|
||||
allTorrents.IterCb(func(_ string, torrent *Torrent) {
|
||||
err := torrent.State.Event(context.Background(), "reset_repair")
|
||||
if err == nil {
|
||||
t.repairLog.Debugf("Repair state of torrent %s has been reset", t.GetKey(torrent))
|
||||
t.writeTorrentToFile(torrent)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ func NewTorrentState(initial string) *fsm.FSM {
|
||||
// when merging with another same hash torrent
|
||||
// when a torrent is rar'ed and not extracting
|
||||
{Name: "mark_as_repaired", Src: []string{"broken_torrent", "under_repair_torrent"}, Dst: "ok_torrent"},
|
||||
// when resetting repair state
|
||||
{Name: "reset_repair", Src: []string{"under_repair_torrent"}, Dst: "broken_torrent"},
|
||||
},
|
||||
fsm.Callbacks{},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user