smart queue fix

This commit is contained in:
Mateusz Gruszczyński
2026-05-05 14:43:58 +02:00
parent df8750bacb
commit 904f36e06f

View File

@@ -272,9 +272,10 @@ def _read_live_start_state(client: Any, torrent_hash: str) -> dict[str, Any]:
result[key] = int(value or 0) if key in {'state', 'active'} else str(value or '') result[key] = int(value or 0) if key in {'state', 'active'} else str(value or '')
except Exception as exc: except Exception as exc:
result[f'{key}_error'] = str(exc) result[f'{key}_error'] = str(exc)
# Note: Dla Smart Queue slot aktywny musi zniknąć z UI jako Paused, więc wymagamy active=1. # Note: rTorrent po masowym d.resume/d.start potrafi długo zwracać d.is_active=0
# state=1 alone może oznaczać nadal zapauzowany torrent po d.pause. # dla torrentów bez bieżącego transferu. Dla Smart Queue start oznacza state=1;
result['started'] = bool(int(result.get('state') or 0)) and bool(int(result.get('active') or 0)) # inaczej weryfikacja zalicza tylko 1 pozycję i kolejne przebiegi dokładają po jednej sztuce.
result['started'] = bool(int(result.get('state') or 0))
return result return result
def _set_smart_queue_label(client: Any, torrent_hash: str, attempts: int = 3) -> bool: def _set_smart_queue_label(client: Any, torrent_hash: str, attempts: int = 3) -> bool:
@@ -351,12 +352,13 @@ def _cleanup_auto_labels(client: Any, profile_id: int, torrents: list[dict[str,
def _is_running_download_slot(t: dict[str, Any]) -> bool: def _is_running_download_slot(t: dict[str, Any]) -> bool:
"""Return True only for torrents that occupy a visible active download slot.""" """Return True for torrents already started by rTorrent."""
# Note: normalize_row oznacza state=1/active=0 jako Paused; takich nie liczymy jako aktywne sloty. # Note: Nie używamy d.is_active/paused do liczenia slotów Smart Queue.
# active=0 może oznaczać brak transferu/peerów, a nie wolny slot. Liczenie po active
# powodowało startowanie kolejki po 1 sztuce mimo targetu 100.
return ( return (
not int(t.get('complete') or 0) not int(t.get('complete') or 0)
and int(t.get('state') or 0) and bool(int(t.get('state') or 0))
and not bool(t.get('paused'))
) )
@@ -396,7 +398,7 @@ def check(profile: dict | None = None, user_id: int | None = None, force: bool =
return str(t.get('label') or '') == SMART_QUEUE_LABEL return str(t.get('label') or '') == SMART_QUEUE_LABEL
# Note: Slot Smart Queue liczymy po d.state, nie po d.is_active. d.is_active bywa 0 # Note: Slot Smart Queue liczymy po d.state, nie po d.is_active. d.is_active bywa 0
# dla torrentu juz wystartowanego, ale chwilowo bez transferu, wiec powodowal startowanie po jednej sztuce. # dla torrentu już wystartowanego, ale chwilowo bez transferu, więc powodował startowanie po jednej sztuce.
downloading = [ downloading = [
t for t in torrents t for t in torrents
if _is_running_download_slot(t) if _is_running_download_slot(t)