fix in queue

This commit is contained in:
Mateusz Gruszczyński
2026-05-05 11:07:54 +02:00
parent eb3d743500
commit dc78f8fd38
5 changed files with 38 additions and 8 deletions

View File

@@ -178,6 +178,18 @@ def _restore_auto_label(client: Any, profile_id: int, torrent_hash: str, current
return False
def _read_live_start_state(client: Any, torrent_hash: str) -> dict[str, Any]:
result: dict[str, Any] = {'hash': torrent_hash}
for key, method in (('state', 'd.state'), ('active', 'd.is_active'), ('message', 'd.message')):
try:
value = client.call(method, torrent_hash)
result[key] = int(value or 0) if key in {'state', 'active'} else str(value or '')
except Exception as exc:
result[f'{key}_error'] = str(exc)
result['started'] = bool(int(result.get('state') or 0) and int(result.get('active') or 0))
return result
def _set_smart_queue_label(client: Any, torrent_hash: str, attempts: int = 3) -> bool:
for attempt in range(max(1, attempts)):
try:
@@ -344,6 +356,8 @@ def check(profile: dict | None = None, user_id: int | None = None, force: bool =
resumed: list[str] = []
label_failed: list[str] = []
start_failed: list[dict[str, str]] = []
start_no_effect: list[dict[str, Any]] = []
resume_requested: list[str] = []
for t in to_pause:
try:
c.call('d.pause', t['hash'])
@@ -360,10 +374,17 @@ def check(profile: dict | None = None, user_id: int | None = None, force: bool =
if bool(t.get('paused')):
c.call('d.resume', h)
c.call('d.start', h)
_restore_auto_label(c, profile_id, h, None)
resumed.append(h)
time.sleep(0.05)
live = _read_live_start_state(c, h)
if live.get('started'):
_restore_auto_label(c, profile_id, h, None)
resumed.append(h)
else:
# Note: Nie liczymy torrenta jako realnie wznowionego, dopóki rTorrent nie potwierdzi state=1 i active=1.
start_no_effect.append(live)
resume_requested.append(h)
except Exception as exc:
start_failed.append({'hash': h, 'error': str(exc)})
restored = _cleanup_auto_labels(c, profile_id, torrents, set(paused), manage_stopped)
add_history(profile_id, 'force_check' if force else 'auto_check', paused, resumed, len(torrents), {'excluded': len(excluded), 'enabled': bool(settings.get('enabled')), 'auto_label': SMART_QUEUE_LABEL, 'labels_restored': restored, 'labels_failed': label_failed, 'start_failed': start_failed, 'manage_stopped': manage_stopped, 'max_active_downloads': max_active, 'active_before': len(downloading), 'active_after': active_after_pause + len(resumed)}, user_id)
return {'ok': True, 'enabled': bool(settings.get('enabled')), 'paused': paused, 'resumed': resumed, 'labels_restored': restored, 'labels_failed': label_failed, 'start_failed': start_failed, 'checked': len(torrents), 'excluded': len(excluded), 'settings': settings}
add_history(profile_id, 'force_check' if force else 'auto_check', paused, resumed, len(torrents), {'excluded': len(excluded), 'enabled': bool(settings.get('enabled')), 'auto_label': SMART_QUEUE_LABEL, 'labels_restored': restored, 'labels_failed': label_failed, 'start_failed': start_failed, 'start_no_effect': start_no_effect, 'resume_requested': resume_requested, 'manage_stopped': manage_stopped, 'max_active_downloads': max_active, 'active_before': len(downloading), 'active_after': active_after_pause + len(resumed)}, user_id)
return {'ok': True, 'enabled': bool(settings.get('enabled')), 'paused': paused, 'resumed': resumed, 'resume_requested': resume_requested, 'labels_restored': restored, 'labels_failed': label_failed, 'start_failed': start_failed, 'start_no_effect': start_no_effect, 'checked': len(torrents), 'excluded': len(excluded), 'settings': settings}