fix: add download progress/completion logging to frontend

Uploads already logged start, every-1-GiB progress, and completion.
Downloads only logged start — now also log:
- Completion with file size (Download complete: file.7z (1.9 GiB))
- Failure with wget exit code
- Periodic progress every ~1 GiB with speed and ETA
This commit is contained in:
Claus Lohmar 2026-07-21 19:40:03 +00:00
parent 6ba7944bb2
commit 5174939939

View file

@ -222,6 +222,7 @@ async def session_upload(
"vm_name": vm_name,
"start_time": time.time(),
"content_length": content_length,
"_last_logged_bytes": 0,
}
return JSONResponse({
@ -261,6 +262,7 @@ async def session_progress(filename: str):
# Process exited
_active_downloads.pop(filename, None)
if poll != 0:
logger.error("Download failed: %s (wget exited with code %d)", filename, poll)
if dest.exists():
dest.unlink(missing_ok=True)
return JSONResponse({
@ -270,6 +272,7 @@ async def session_progress(filename: str):
})
# Success
final_bytes = dest.stat().st_size
logger.info("Download complete: %s (%.1f GiB)", filename, final_bytes / (1024**3))
return JSONResponse({
"phase": "complete",
"file_size_bytes": final_bytes,
@ -320,6 +323,14 @@ async def session_progress(filename: str):
# Already handled above; this line is unreachable but kept for clarity
pass
# Log progress periodically (every ~1 GiB)
last_logged = info.get("_last_logged_bytes", 0)
if current_bytes - last_logged >= 1024**3:
info["_last_logged_bytes"] = current_bytes
logger.info("Downloading: %s%.1f GiB (%.1f MB/s)%s",
filename, current_bytes / (1024**3), speed_mbps,
f" ETA {eta_str}" if eta_str else "")
return JSONResponse({
"phase": "downloading",
"file_size_bytes": current_bytes,