stop and continue for task
This commit is contained in:
@@ -67,6 +67,12 @@ def test_http_api_validates_and_snapshots_settings(tmp_path: Path) -> None:
|
||||
assert task[1]["proxy"] == "http://127.0.0.1:7890"
|
||||
assert task[1]["output_dir"] == str(config.download_root / "batch")
|
||||
assert "m3u8_referer" not in task[1]["items"][0]
|
||||
paused = _request(base, f"/api/tasks/{task[1]['id']}/pause", {})
|
||||
assert paused[0] == 200
|
||||
assert paused[1]["status"] == "paused"
|
||||
resumed = _request(base, f"/api/tasks/{task[1]['id']}/resume", {})
|
||||
assert resumed[0] == 200
|
||||
assert resumed[1]["status"] == "running"
|
||||
service.store.log("error", "Expected log entry")
|
||||
logs = _get(base, "/api/logs?level=error")
|
||||
assert logs[0] == 200
|
||||
@@ -125,6 +131,57 @@ def test_tasks_and_settings_are_not_retained_after_restart(tmp_path: Path) -> No
|
||||
assert restarted.bootstrap()["settings"]["max_active_downloads"] == 1
|
||||
|
||||
|
||||
def test_pause_waits_for_running_item_then_resumes_at_download_queue_tail(tmp_path: Path) -> None:
|
||||
store = TaskState(tmp_path)
|
||||
payload = [_item("http://127.0.0.1"), {**_item("http://127.0.0.1"), "code": "episode-2", "title": "episode-2"}]
|
||||
task_id = store.create_task(
|
||||
title="batch",
|
||||
base_dir=tmp_path,
|
||||
output_dir=tmp_path / "batch",
|
||||
proxy="",
|
||||
items=decode_download_items(json.dumps(payload)),
|
||||
)
|
||||
|
||||
claimed = store.claim_next_item()
|
||||
assert claimed is not None
|
||||
_, first = claimed
|
||||
assert store.pause_task(task_id)
|
||||
pausing = store.get_task(task_id)
|
||||
assert pausing is not None
|
||||
assert pausing["status"] == "pausing"
|
||||
assert pausing["items"][1]["status"] == "paused"
|
||||
|
||||
store.mark_item_paused(int(first["id"]), "download")
|
||||
paused = store.get_task(task_id)
|
||||
assert paused is not None
|
||||
assert paused["status"] == "paused"
|
||||
|
||||
resumed = store.resume_task(task_id)
|
||||
assert resumed == ([int(first["id"]), int(paused["items"][1]["id"])], [])
|
||||
next_claimed = store.claim_next_item()
|
||||
assert next_claimed is not None
|
||||
_, next_item = next_claimed
|
||||
assert next_item["id"] == first["id"]
|
||||
|
||||
|
||||
def test_cancelling_a_paused_task_reaches_cancelled(tmp_path: Path) -> None:
|
||||
store = TaskState(tmp_path)
|
||||
task_id = store.create_task(
|
||||
title="batch",
|
||||
base_dir=tmp_path,
|
||||
output_dir=tmp_path / "batch",
|
||||
proxy="",
|
||||
items=decode_download_items(json.dumps([_item("http://127.0.0.1")])),
|
||||
)
|
||||
|
||||
assert store.pause_task(task_id)
|
||||
assert store.get_task(task_id)["status"] == "paused" # type: ignore[index]
|
||||
assert store.cancel_task(task_id)
|
||||
cancelled = store.get_task(task_id)
|
||||
assert cancelled is not None
|
||||
assert cancelled["status"] == "cancelled"
|
||||
|
||||
|
||||
def test_runner_runs_multiple_videos_from_one_task_concurrently(tmp_path: Path) -> None:
|
||||
store = TaskState(tmp_path, max_active_downloads=2)
|
||||
runner = TaskRunner(store, worker_capacity=2, ffmpeg="ffmpeg")
|
||||
|
||||
Reference in New Issue
Block a user