feat: 未知进度不显示进度条并增加任务详情
This commit is contained in:
@@ -81,6 +81,7 @@ class DownloadJob:
|
||||
"completed": self.completed,
|
||||
"failed": self.failed,
|
||||
"writtenRows": self.written_rows,
|
||||
"fileBytes": _file_bytes(self.csv_path),
|
||||
"csvPath": str(self.csv_path),
|
||||
"failures": self.failures[-20:],
|
||||
"createdAt": self.created_at,
|
||||
@@ -122,6 +123,15 @@ class DownloadJob:
|
||||
await subscriber.put(event)
|
||||
|
||||
|
||||
def _file_bytes(path: str | Path) -> int:
|
||||
if not path:
|
||||
return 0
|
||||
try:
|
||||
return Path(path).stat().st_size
|
||||
except OSError:
|
||||
return 0
|
||||
|
||||
|
||||
def _set_event() -> asyncio.Event:
|
||||
event = asyncio.Event()
|
||||
event.set()
|
||||
@@ -353,6 +363,7 @@ class JobManager:
|
||||
"completed": finished or data.get("completed") or 0,
|
||||
"failed": data.get("failed") or 0,
|
||||
"writtenRows": written or data.get("writtenRows") or 0,
|
||||
"fileBytes": _file_bytes(data.get("csvPath") or ""),
|
||||
"csvPath": data.get("csvPath"),
|
||||
"failures": data.get("failures") or [],
|
||||
"createdAt": data.get("createdAt"),
|
||||
|
||||
@@ -402,6 +402,45 @@ def test_refresh_saved_session_rewrites_cookie(tmp_path: Path, monkeypatch):
|
||||
assert stored[0]["cookies"][0]["value"] == "kept"
|
||||
|
||||
|
||||
def test_snapshot_reports_csv_size(tmp_path: Path):
|
||||
csv_path = tmp_path / "out.csv"
|
||||
csv_path.write_bytes(b"abcdef")
|
||||
job = DownloadJob(
|
||||
id="20260921120009",
|
||||
directory=tmp_path,
|
||||
network="NR",
|
||||
city_code="JM",
|
||||
city_name="江门",
|
||||
month="2026-09",
|
||||
groups=["rsrp"],
|
||||
concurrency=2,
|
||||
grid_ids=["1", "2"],
|
||||
csv_path=csv_path,
|
||||
created_at="2026-09-21T12:00:09",
|
||||
whole_city=True,
|
||||
listing_done=False,
|
||||
discovered=4,
|
||||
)
|
||||
snap = job.snapshot()
|
||||
assert snap["fileBytes"] == 6
|
||||
assert snap["listingDone"] is False
|
||||
assert snap["total"] == 4
|
||||
missing = DownloadJob(
|
||||
id="20260921120010",
|
||||
directory=tmp_path,
|
||||
network="LTE",
|
||||
city_code="JM",
|
||||
city_name="江门",
|
||||
month="2026-09",
|
||||
groups=["rsrp"],
|
||||
concurrency=1,
|
||||
grid_ids=[],
|
||||
csv_path=tmp_path / "missing.csv",
|
||||
created_at="",
|
||||
)
|
||||
assert missing.snapshot()["fileBytes"] == 0
|
||||
|
||||
|
||||
def test_task_folder_uses_second_timestamp(tmp_path: Path, monkeypatch):
|
||||
monkeypatch.setattr(job_module, "DATA_DIR", tmp_path / "jobs")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user