This commit is contained in:
2026-03-04 16:50:28 -08:00
parent 4110c5ec00
commit f103496a00

View File

@@ -207,9 +207,13 @@ class HydrusNetwork:
# Keep the PipelineLiveProgress transfer line clean: show the file name. # Keep the PipelineLiveProgress transfer line clean: show the file name.
# (The hydrus instance/service is already visible in the logs above.) # (The hydrus instance/service is already visible in the logs above.)
label = str(getattr(file_path, "name", None) or "upload") label = str(getattr(file_path, "name", None) or "upload")
start_t = time.time() traffic_sent_total = [0]
last_render_t = [start_t]
sent = [0] upload_attempts = 3
last_upload_exc: Exception | None = None
for attempt in range(upload_attempts):
sent_this_attempt = [0]
last_render_t = [time.time()]
def _render_progress(final: bool = False) -> None: def _render_progress(final: bool = False) -> None:
if file_size <= 0: if file_size <= 0:
@@ -219,7 +223,7 @@ class HydrusNetwork:
return return
last_render_t[0] = now last_render_t[0] = now
bar.update( bar.update(
downloaded=int(sent[0]), downloaded=int(sent_this_attempt[0]),
total=int(file_size), total=int(file_size),
label=str(label), label=str(label),
file=sys.stderr, file=sys.stderr,
@@ -234,15 +238,13 @@ class HydrusNetwork:
chunk = handle.read(chunk_size) chunk = handle.read(chunk_size)
if not chunk: if not chunk:
break break
sent[0] += len(chunk) sent_this_attempt[0] += len(chunk)
traffic_sent_total[0] += len(chunk)
_render_progress(final=False) _render_progress(final=False)
yield chunk yield chunk
finally: finally:
_render_progress(final=True) _render_progress(final=True)
upload_attempts = 3
last_upload_exc: Exception | None = None
for attempt in range(upload_attempts):
try: try:
response = client.request( response = client.request(
spec.method, spec.method,
@@ -253,14 +255,23 @@ class HydrusNetwork:
raise_for_status=False, raise_for_status=False,
log_http_errors=False, log_http_errors=False,
) )
logger.debug(
f"{self._log_prefix()} Upload completed on attempt {attempt + 1}/{upload_attempts}; "
f"attempt_bytes={int(sent_this_attempt[0])}, total_traffic_bytes={int(traffic_sent_total[0])}"
)
last_upload_exc = None last_upload_exc = None
break break
except (httpx.TimeoutException, httpx.RequestError) as exc: except (httpx.TimeoutException, httpx.RequestError) as exc:
last_upload_exc = exc last_upload_exc = exc
logger.warning( logger.warning(
f"{self._log_prefix()} Upload timeout/error on attempt {attempt + 1}/{upload_attempts}: {exc}" f"{self._log_prefix()} Upload timeout/error on attempt {attempt + 1}/{upload_attempts}: {exc} "
f"(attempt_bytes={int(sent_this_attempt[0])}, total_traffic_bytes={int(traffic_sent_total[0])})"
) )
if attempt < upload_attempts - 1: if attempt < upload_attempts - 1:
try:
time.sleep(0.75 * (attempt + 1))
except Exception:
pass
continue continue
raise raise
if response is None and last_upload_exc is not None: if response is None and last_upload_exc is not None: