Support rebooting workers
This commit is contained in:
@@ -177,21 +177,21 @@ func (z *ZurgConfig) EnableDownloadMount() bool {
|
|||||||
|
|
||||||
func (z *ZurgConfig) GetApiTimeoutSecs() int {
|
func (z *ZurgConfig) GetApiTimeoutSecs() int {
|
||||||
if z.ApiTimeoutSecs == 0 {
|
if z.ApiTimeoutSecs == 0 {
|
||||||
return 30
|
return 15
|
||||||
}
|
}
|
||||||
return z.ApiTimeoutSecs
|
return z.ApiTimeoutSecs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *ZurgConfig) GetDownloadTimeoutSecs() int {
|
func (z *ZurgConfig) GetDownloadTimeoutSecs() int {
|
||||||
if z.DownloadTimeoutSecs == 0 {
|
if z.DownloadTimeoutSecs == 0 {
|
||||||
return 15
|
return 10
|
||||||
}
|
}
|
||||||
return z.DownloadTimeoutSecs
|
return z.DownloadTimeoutSecs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *ZurgConfig) GetRateLimitSleepSecs() int {
|
func (z *ZurgConfig) GetRateLimitSleepSecs() int {
|
||||||
if z.RateLimitSleepSecs == 0 {
|
if z.RateLimitSleepSecs == 0 {
|
||||||
return 4
|
return 6
|
||||||
}
|
}
|
||||||
return z.RateLimitSleepSecs
|
return z.RateLimitSleepSecs
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,6 +243,8 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
|
|||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
<button type="button" onclick="window.open('/logs/upload')">Upload logs</button>
|
<button type="button" onclick="window.open('/logs/upload')">Upload logs</button>
|
||||||
<button type="button" onclick="window.open('/reboot/worker')">Reboot worker pool</button>
|
<button type="button" onclick="window.open('/reboot/worker')">Reboot worker pool</button>
|
||||||
|
<button type="button" onclick="window.open('/reboot/refresh')">Reboot refresh worker</button>
|
||||||
|
<button type="button" onclick="window.open('/reboot/repair')">Reboot repair worker</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@@ -310,6 +312,20 @@ func (zr *Handlers) handleRebootWorkerPool(resp http.ResponseWriter, req *http.R
|
|||||||
fmt.Fprint(resp, "Rebooted worker pool, please close this window")
|
fmt.Fprint(resp, "Rebooted worker pool, please close this window")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (zr *Handlers) handleRebootRefreshPool(resp http.ResponseWriter, req *http.Request) {
|
||||||
|
zr.torMgr.RefreshKillSwitch <- struct{}{}
|
||||||
|
zr.torMgr.StartRefreshJob()
|
||||||
|
zr.log.Infof("Rebooted refresh worker")
|
||||||
|
fmt.Fprint(resp, "Rebooted refresh worker, please close this window")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (zr *Handlers) handleRebootRepairPool(resp http.ResponseWriter, req *http.Request) {
|
||||||
|
zr.torMgr.RepairKillSwitch <- struct{}{}
|
||||||
|
zr.torMgr.StartRepairJob()
|
||||||
|
zr.log.Infof("Rebooted repair worker")
|
||||||
|
fmt.Fprint(resp, "Rebooted repair worker, please close this window")
|
||||||
|
}
|
||||||
|
|
||||||
func bToMb(b uint64) uint64 {
|
func bToMb(b uint64) uint64 {
|
||||||
return b / 1024 / 1024
|
return b / 1024 / 1024
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ func AttachHandlers(router *chi.Mux, downloader *universal.Downloader, torMgr *t
|
|||||||
|
|
||||||
router.Get("/", hs.handleHome)
|
router.Get("/", hs.handleHome)
|
||||||
router.Get("/reboot/worker", hs.handleRebootWorkerPool)
|
router.Get("/reboot/worker", hs.handleRebootWorkerPool)
|
||||||
|
router.Get("/reboot/refresh", hs.handleRebootRefreshPool)
|
||||||
|
router.Get("/reboot/repair", hs.handleRebootRepairPool)
|
||||||
// version
|
// version
|
||||||
router.Get(fmt.Sprintf("/{mountType}/%s", version.FILE), hs.handleVersionFile)
|
router.Get(fmt.Sprintf("/{mountType}/%s", version.FILE), hs.handleVersionFile)
|
||||||
router.Head(fmt.Sprintf("/{mountType}/%s", version.FILE), hs.handleCheckVersionFile)
|
router.Head(fmt.Sprintf("/{mountType}/%s", version.FILE), hs.handleCheckVersionFile)
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ type TorrentManager struct {
|
|||||||
requiredVersion string
|
requiredVersion string
|
||||||
workerPool *ants.Pool
|
workerPool *ants.Pool
|
||||||
refreshPool *ants.Pool
|
refreshPool *ants.Pool
|
||||||
|
RefreshKillSwitch chan struct{}
|
||||||
|
RepairKillSwitch chan struct{}
|
||||||
repairPool *ants.Pool
|
repairPool *ants.Pool
|
||||||
repairTrigger chan *Torrent
|
repairTrigger chan *Torrent
|
||||||
repairSet mapset.Set[*Torrent]
|
repairSet mapset.Set[*Torrent]
|
||||||
@@ -51,6 +53,8 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
|
|||||||
DirectoryMap: cmap.New[cmap.ConcurrentMap[string, *Torrent]](),
|
DirectoryMap: cmap.New[cmap.ConcurrentMap[string, *Torrent]](),
|
||||||
DownloadCache: cmap.New[*realdebrid.Download](),
|
DownloadCache: cmap.New[*realdebrid.Download](),
|
||||||
DownloadMap: cmap.New[*realdebrid.Download](),
|
DownloadMap: cmap.New[*realdebrid.Download](),
|
||||||
|
RefreshKillSwitch: make(chan struct{}, 1),
|
||||||
|
RepairKillSwitch: make(chan struct{}, 1),
|
||||||
fixers: cmap.New[*Torrent](),
|
fixers: cmap.New[*Torrent](),
|
||||||
deleteOnceDone: mapset.NewSet[string](),
|
deleteOnceDone: mapset.NewSet[string](),
|
||||||
allAccessKeys: mapset.NewSet[string](),
|
allAccessKeys: mapset.NewSet[string](),
|
||||||
|
|||||||
@@ -123,9 +123,12 @@ func (t *TorrentManager) refreshTorrents() []string {
|
|||||||
func (t *TorrentManager) StartRefreshJob() {
|
func (t *TorrentManager) StartRefreshJob() {
|
||||||
_ = t.refreshPool.Submit(func() {
|
_ = t.refreshPool.Submit(func() {
|
||||||
t.log.Info("Starting periodic refresh job")
|
t.log.Info("Starting periodic refresh job")
|
||||||
for {
|
refreshTicker := time.NewTicker(time.Duration(t.Config.GetRefreshEverySecs()) * time.Second)
|
||||||
<-time.After(time.Duration(t.Config.GetRefreshEverySecs()) * time.Second)
|
defer refreshTicker.Stop()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-refreshTicker.C:
|
||||||
checksum := t.getCurrentState()
|
checksum := t.getCurrentState()
|
||||||
if t.latestState.equal(checksum) {
|
if t.latestState.equal(checksum) {
|
||||||
continue
|
continue
|
||||||
@@ -137,6 +140,10 @@ func (t *TorrentManager) StartRefreshJob() {
|
|||||||
t.log.Info("Finished refreshing torrents")
|
t.log.Info("Finished refreshing torrents")
|
||||||
|
|
||||||
t.TriggerHookOnLibraryUpdate(updatedPaths)
|
t.TriggerHookOnLibraryUpdate(updatedPaths)
|
||||||
|
case <-t.RefreshKillSwitch:
|
||||||
|
t.log.Info("Stopping periodic refresh job")
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ func (t *TorrentManager) StartRepairJob() {
|
|||||||
case torrent := <-t.repairTrigger:
|
case torrent := <-t.repairTrigger:
|
||||||
// On-demand trigger with a specific torrent
|
// On-demand trigger with a specific torrent
|
||||||
t.invokeRepair(torrent)
|
t.invokeRepair(torrent)
|
||||||
|
case <-t.RepairKillSwitch:
|
||||||
|
t.log.Info("Stopping periodic repair job")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ func (r *HTTPClient) shouldRetry(resp *http.Response, reqHasRangeHeader bool, er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil && strings.Contains(err.Error(), "timeout awaiting response headers") {
|
if err != nil && strings.Contains(err.Error(), "timeout") {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user