Добавил "усыновление" существующих торрентов при добавлении тега или
категории
This commit is contained in:
@@ -31,6 +31,10 @@ type Store interface {
|
||||
GetDownload(ctx context.Context, id int64) (*store.Download, error)
|
||||
SetDownloadState(ctx context.Context, id int64, state store.State, errCode, errMsg string) error
|
||||
|
||||
// Discovery (усыновление раздач по категории/тегу).
|
||||
ExistsByInfohash(ctx context.Context, infohash string) (bool, error)
|
||||
CreateDownload(ctx context.Context, d *store.Download) (int64, error)
|
||||
|
||||
// Ф3: распознавание, ревью, раскладка.
|
||||
CreateRecognition(ctx context.Context, r *store.Recognition, reasons []string) (int64, error)
|
||||
GetCurrentRecognition(ctx context.Context, downloadID int64) (*store.Recognition, error)
|
||||
@@ -85,6 +89,7 @@ type Notifier interface {
|
||||
// Config — параметры воркера.
|
||||
type Config struct {
|
||||
Category string
|
||||
Tag string // метка для усыновления существующих раздач (discovery)
|
||||
SavePath string
|
||||
PollInterval time.Duration
|
||||
StuckAfter time.Duration // stalledDL дольше → stuck
|
||||
@@ -158,8 +163,10 @@ func (w *Worker) pollOnce(ctx context.Context) {
|
||||
}
|
||||
|
||||
// Poll сверяет активные задачи с состоянием qBittorrent и двигает их.
|
||||
// Листаем все торренты (а не только свою категорию), чтобы reconcile нашёл и
|
||||
// усыновлённые по тегу раздачи, а discovery — увидел новые.
|
||||
func (w *Worker) Poll(ctx context.Context) error {
|
||||
torrents, err := w.qbt.Torrents(ctx, w.cfg.Category)
|
||||
torrents, err := w.qbt.Torrents(ctx, "")
|
||||
if err != nil {
|
||||
return fmt.Errorf("poll: list torrents: %w", err)
|
||||
}
|
||||
@@ -175,6 +182,9 @@ func (w *Worker) Poll(ctx context.Context) error {
|
||||
w.mu.Lock()
|
||||
defer w.mu.Unlock()
|
||||
|
||||
// Усыновляем новые раздачи с нашей категорией/тегом до reconcile.
|
||||
w.discover(ctx, torrents)
|
||||
|
||||
active, err := w.store.ListDownloadsByState(ctx, store.StateDownloading)
|
||||
if err != nil {
|
||||
return fmt.Errorf("poll: list active: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user