fix: 显示任务传输状态
This commit is contained in:
+21
-4
@@ -605,7 +605,7 @@ def start_schedule(row: sqlite3.Row, trigger: str) -> None:
|
||||
"srcFs": row["src"],
|
||||
"dstFs": row["dst"],
|
||||
"_async": True,
|
||||
"_group": f"webgui/recurring/{schedule_id}/{action}",
|
||||
"_group": transfer_group("recurring", schedule_id, action),
|
||||
}
|
||||
if action == "move":
|
||||
payload["deleteEmptySrcDirs"] = True
|
||||
@@ -686,7 +686,7 @@ def start_one_time_job(job_id: int) -> None:
|
||||
"srcFs": row["src"],
|
||||
"dstFs": row["dst"],
|
||||
"_async": True,
|
||||
"_group": f"webgui/once/{job_id}/{action}",
|
||||
"_group": transfer_group("once", job_id, action),
|
||||
}
|
||||
if action == "move":
|
||||
payload["deleteEmptySrcDirs"] = True
|
||||
@@ -744,6 +744,23 @@ def status_name(status: dict[str, Any]) -> str:
|
||||
return "finished"
|
||||
|
||||
|
||||
def transfer_group(kind: str, record_id: int, action: str) -> str:
|
||||
return f"webgui/{kind}/{record_id}/{action}"
|
||||
|
||||
|
||||
def status_with_stats(kind: str, row: sqlite3.Row, jobid: int) -> dict[str, Any]:
|
||||
status = rc_post("job/status", {"jobid": jobid}, timeout=15, allow_error_body=True)
|
||||
group = transfer_group(kind, int(row["id"]), row["action"])
|
||||
try:
|
||||
stats = rc_post("core/stats", {"group": group}, timeout=15, allow_error_body=True)
|
||||
except Exception as exc:
|
||||
stats = {"error": str(exc)}
|
||||
status["stats"] = stats
|
||||
if "group" not in status:
|
||||
status["group"] = group
|
||||
return status
|
||||
|
||||
|
||||
def refresh_running_jobs() -> None:
|
||||
with db_lock, connect() as conn:
|
||||
rows = conn.execute("SELECT * FROM job_schedules WHERE current_jobid IS NOT NULL").fetchall()
|
||||
@@ -752,7 +769,7 @@ def refresh_running_jobs() -> None:
|
||||
schedule_id = int(row["id"])
|
||||
jobid = int(row["current_jobid"])
|
||||
try:
|
||||
status = rc_post("job/status", {"jobid": jobid}, timeout=15, allow_error_body=True)
|
||||
status = status_with_stats("recurring", row, jobid)
|
||||
except Exception as exc:
|
||||
status = {"finished": True, "error": str(exc), "jobid": jobid}
|
||||
apply_status(row, status)
|
||||
@@ -765,7 +782,7 @@ def refresh_one_time_jobs() -> None:
|
||||
for row in rows:
|
||||
jobid = int(row["jobid"])
|
||||
try:
|
||||
status = rc_post("job/status", {"jobid": jobid}, timeout=15, allow_error_body=True)
|
||||
status = status_with_stats("once", row, jobid)
|
||||
except Exception as exc:
|
||||
status = {"finished": True, "error": str(exc), "jobid": jobid}
|
||||
apply_one_time_status(row, status)
|
||||
|
||||
@@ -128,7 +128,18 @@ class OneTimeJobTest(unittest.TestCase):
|
||||
self.next_jobid += 1
|
||||
return {"jobid": self.next_jobid}
|
||||
if path == "job/status":
|
||||
return {"finished": False, "jobid": payload["jobid"], "progress": {"bytes": 1, "totalBytes": 2}}
|
||||
return {"finished": False, "jobid": payload["jobid"]}
|
||||
if path == "core/stats":
|
||||
return {
|
||||
"bytes": 1,
|
||||
"totalBytes": 2,
|
||||
"speed": 3,
|
||||
"eta": 4,
|
||||
"transfers": 5,
|
||||
"totalTransfers": 6,
|
||||
"errors": 7,
|
||||
"group": payload["group"],
|
||||
}
|
||||
if path == "job/stop":
|
||||
return {}
|
||||
raise AssertionError(path)
|
||||
@@ -153,6 +164,9 @@ class OneTimeJobTest(unittest.TestCase):
|
||||
self.assertEqual(len(jobs), 1)
|
||||
self.assertEqual(jobs[0]["id"], 1)
|
||||
self.assertEqual(jobs[0]["status"], "running")
|
||||
self.assertEqual(jobs[0]["statusSnapshot"]["stats"]["bytes"], 1)
|
||||
self.assertEqual(jobs[0]["statusSnapshot"]["stats"]["totalBytes"], 2)
|
||||
self.assertEqual(jobs[0]["statusSnapshot"]["stats"]["speed"], 3)
|
||||
|
||||
def test_stop_one_time_job_persists_stopped_status(self):
|
||||
job = server.create_one_time_job({"action": "copy", "src": "/tmp/a", "dst": "/tmp/b"})
|
||||
|
||||
Reference in New Issue
Block a user