This commit is contained in:
Mukhtar Akere
2025-02-28 03:10:14 +01:00
parent 65fb2d1e7c
commit f04d7ac86e
7 changed files with 9 additions and 24 deletions

View File

@@ -194,7 +194,6 @@ func (ad *AllDebrid) CheckStatus(torrent *torrent.Torrent, isSymlink bool) (*tor
break
} else if status == "downloading" {
if !ad.DownloadUncached {
go ad.DeleteTorrent(torrent)
return torrent, fmt.Errorf("torrent: %s not cached", torrent.Name)
}
// Break out of the loop if the torrent is downloading.

View File

@@ -218,7 +218,6 @@ func (dl *DebridLink) CheckStatus(torrent *torrent.Torrent, isSymlink bool) (*to
break
} else if status == "downloading" {
if !dl.DownloadUncached {
go dl.DeleteTorrent(torrent)
return torrent, fmt.Errorf("torrent: %s not cached", torrent.Name)
}
// Break out of the loop if the torrent is downloading.

View File

@@ -249,7 +249,6 @@ func (r *RealDebrid) CheckStatus(t *torrent.Torrent, isSymlink bool) (*torrent.T
break
} else if slices.Contains(downloadingStatus, status) {
if !r.DownloadUncached {
go r.DeleteTorrent(t)
return t, fmt.Errorf("torrent: %s not cached", t.Name)
}
// Break out of the loop if the torrent is downloading.

View File

@@ -234,7 +234,6 @@ func (tb *Torbox) CheckStatus(torrent *torrent.Torrent, isSymlink bool) (*torren
break
} else if status == "downloading" {
if !tb.DownloadUncached {
go tb.DeleteTorrent(torrent)
return torrent, fmt.Errorf("torrent: %s not cached", torrent.Name)
}
// Break out of the loop if the torrent is downloading.

View File

@@ -74,7 +74,6 @@ func (i *ImportRequest) Process(q *QBit) (err error) {
torrent := CreateTorrentFromMagnet(magnet, i.Arr.Name, "manual")
debridTorrent, err := debrid.ProcessTorrent(svc.Debrid, magnet, i.Arr, i.IsSymlink)
if err != nil || debridTorrent == nil {
fmt.Println("Error deleting torrent: ", err)
if debridTorrent != nil {
dbClient := service.GetDebrid().GetByName(debridTorrent.Debrid)
go dbClient.DeleteTorrent(debridTorrent)

View File

@@ -436,7 +436,7 @@ func (ui *Handler) handleGetConfig(w http.ResponseWriter, r *http.Request) {
arrCfgs := make([]config.Arr, 0)
svc := service.GetService()
for _, a := range svc.Arr.GetAll() {
arrCfgs = append(arrCfgs, config.Arr{Host: a.Host, Name: a.Name, Token: a.Token})
arrCfgs = append(arrCfgs, config.Arr{Host: a.Host, Name: a.Name, Token: a.Token, Cleanup: a.Cleanup})
}
cfg.Arrs = arrCfgs
request.JSONResponse(w, cfg, http.StatusOK)

View File

@@ -5,7 +5,6 @@ import (
"github.com/rs/zerolog"
"github.com/sirrobot01/debrid-blackhole/internal/config"
"github.com/sirrobot01/debrid-blackhole/internal/logger"
"github.com/sirrobot01/debrid-blackhole/pkg/arr"
"github.com/sirrobot01/debrid-blackhole/pkg/service"
"os"
"sync"
@@ -68,17 +67,6 @@ func arrRefreshWorker(ctx context.Context, cfg *config.Config) {
func cleanUpQueuesWorker(ctx context.Context, cfg *config.Config) {
// Start Clean up Queues Worker
_logger := getLogger()
_arrs := service.GetService().Arr
filtered := make([]*arr.Arr, 0)
for _, a := range _arrs.GetAll() {
if a.Cleanup {
filtered = append(filtered, a)
}
}
if len(filtered) == 0 {
_logger.Debug().Msg("No ARR instances configured for cleanup")
return
}
_logger.Debug().Msg("Clean up Queues Worker started")
cleanupCtx := context.WithValue(ctx, "worker", "cleanup")
cleanupTicker := time.NewTicker(time.Duration(10) * time.Second)
@@ -94,7 +82,7 @@ func cleanUpQueuesWorker(ctx context.Context, cfg *config.Config) {
if cleanupMutex.TryLock() {
go func() {
defer cleanupMutex.Unlock()
cleanUpQueues(filtered)
cleanUpQueues()
}()
}
}
@@ -102,21 +90,23 @@ func cleanUpQueuesWorker(ctx context.Context, cfg *config.Config) {
}
func refreshArrs() {
arrs := service.GetService().Arr
for _, a := range arrs.GetAll() {
for _, a := range service.GetService().Arr.GetAll() {
err := a.Refresh()
if err != nil {
_logger := getLogger()
_logger.Debug().Err(err).Msgf("Error refreshing %s", a.Name)
_logger.Debug().Err(err).Msg("Error refreshing arr")
return
}
}
}
func cleanUpQueues(arrs []*arr.Arr) {
func cleanUpQueues() {
// Clean up queues
_logger := getLogger()
for _, a := range arrs {
for _, a := range service.GetService().Arr.GetAll() {
if !a.Cleanup {
continue
}
_logger.Debug().Msgf("Cleaning up queue for %s", a.Name)
if err := a.CleanupQueue(); err != nil {
_logger.Debug().Err(err).Msg("Error cleaning up queue")