smart queue fix
This commit is contained in:
@@ -1166,6 +1166,54 @@ def apply_startup_overrides(profile: dict) -> dict:
|
||||
return {"ok": True, "updated": [], "errors": [], "skipped": True}
|
||||
return set_config(profile, values, apply_now=True, apply_on_start=True)
|
||||
|
||||
|
||||
def start_or_resume_hash(c: ScgiRtorrentClient, torrent_hash: str) -> dict:
|
||||
"""Start stopped torrents and resume torrents paused with d.pause."""
|
||||
h = str(torrent_hash or '')
|
||||
if not h:
|
||||
return {'hash': h, 'ok': False, 'error': 'missing hash'}
|
||||
|
||||
result: dict = {'hash': h, 'commands': []}
|
||||
try:
|
||||
result['state_before'] = int(c.call('d.state', h) or 0)
|
||||
except Exception as exc:
|
||||
result['state_before_error'] = str(exc)
|
||||
result['state_before'] = 0
|
||||
|
||||
# Note: Ręczne Start i Smart Queue muszą zdejmować pause przez d.resume; samo d.start
|
||||
# nie rusza torrentów zatrzymanych wcześniej komendą d.pause.
|
||||
for method in ('d.resume',):
|
||||
try:
|
||||
c.call(method, h)
|
||||
result['commands'].append(method)
|
||||
except Exception as exc:
|
||||
result.setdefault('ignored_errors', []).append(f'{method}: {exc}')
|
||||
|
||||
# Note: d.open bywa potrzebne po całkowitym stop/close; dla już otwartych torrentów jest bezpiecznie ignorowane.
|
||||
try:
|
||||
c.call('d.open', h)
|
||||
result['commands'].append('d.open')
|
||||
except Exception as exc:
|
||||
result.setdefault('ignored_errors', []).append(f'd.open: {exc}')
|
||||
|
||||
for method in ('d.start', 'd.resume', 'd.try_start'):
|
||||
try:
|
||||
c.call(method, h)
|
||||
result['commands'].append(method)
|
||||
except Exception as exc:
|
||||
result.setdefault('ignored_errors', []).append(f'{method}: {exc}')
|
||||
|
||||
try:
|
||||
result['state_after'] = int(c.call('d.state', h) or 0)
|
||||
except Exception as exc:
|
||||
result['state_after_error'] = str(exc)
|
||||
try:
|
||||
result['active_after'] = int(c.call('d.is_active', h) or 0)
|
||||
except Exception as exc:
|
||||
result['active_after_error'] = str(exc)
|
||||
result['ok'] = True
|
||||
return result
|
||||
|
||||
def action(profile: dict, torrent_hashes: list[str], name: str, payload: dict | None = None) -> dict:
|
||||
payload = payload or {}
|
||||
c = client_for(profile)
|
||||
@@ -1241,6 +1289,11 @@ def action(profile: dict, torrent_hashes: list[str], name: str, payload: dict |
|
||||
c.call("d.directory.set", h, path)
|
||||
results.append(item)
|
||||
return {"ok": True, "count": len(torrent_hashes), "move_data": move_data, "results": results}
|
||||
if name in {"start", "resume"}:
|
||||
# Note: Start działa teraz także dla pozycji Paused, bo wykonuje pełną sekwencję resume/open/start.
|
||||
results = [start_or_resume_hash(c, h) for h in torrent_hashes]
|
||||
return {"ok": True, "count": len(torrent_hashes), "remove_data": False, "results": results}
|
||||
|
||||
method = methods.get(name)
|
||||
if not method:
|
||||
raise ValueError(f"Unknown action: {name}")
|
||||
|
||||
Reference in New Issue
Block a user