add strem like procedure and log progress (#13828)
This commit is contained in:
parent
985f170383
commit
bc6371aa83
1 changed files with 14 additions and 3 deletions
|
@ -146,11 +146,22 @@ async def insert_from_delta_file(
|
|||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(server_info.url + "/" + filename, timeout=timeout) as resp:
|
||||
resp.raise_for_status()
|
||||
|
||||
size = int(resp.headers.get("content-length", 0))
|
||||
log.debug(f"Downloading delta file {filename}. Size {size} bytes.")
|
||||
progress_byte = 0
|
||||
progress_percentage = "{:.0%}".format(0)
|
||||
target_filename = client_foldername.joinpath(filename)
|
||||
text = await resp.read()
|
||||
target_filename.write_bytes(text)
|
||||
with target_filename.open(mode="wb") as f:
|
||||
async for chunk, _ in resp.content.iter_chunks():
|
||||
f.write(chunk)
|
||||
progress_byte += len(chunk)
|
||||
new_percentage = "{:.0%}".format(progress_byte / size)
|
||||
if new_percentage != progress_percentage:
|
||||
progress_percentage = new_percentage
|
||||
log.info(f"Downloading delta file {filename}. {progress_percentage} of {size} bytes.")
|
||||
except Exception:
|
||||
target_filename = client_foldername.joinpath(filename)
|
||||
os.remove(target_filename)
|
||||
await data_store.server_misses_file(tree_id, server_info, timestamp)
|
||||
raise
|
||||
|
||||
|
|
Loading…
Reference in a new issue