This commit is contained in:
2026-03-04 16:50:19 -08:00
parent 818d0c0338
commit 4110c5ec00
6 changed files with 379 additions and 77 deletions

View File

@@ -73,6 +73,8 @@ class HydrusNetwork:
url: str
access_key: str = ""
timeout: float = 9.0
upload_io_timeout: float = 120.0
upload_chunk_size: int = 64 * 1024
instance_name: str = "" # Optional store name (e.g., 'home') for namespaced logs
scheme: str = field(init=False)
@@ -167,6 +169,37 @@ class HydrusNetwork:
f"{self._log_prefix()} Uploading file {file_path.name} ({file_size} bytes)"
)
# Upload timeout policy:
# - Keep normal requests fast via `self.timeout`.
# - For streaming uploads, use an activity timeout for read/write so
# long transfers do not fail due to a short generic timeout.
# - If upload_io_timeout <= 0, disable read/write timeout entirely.
try:
upload_io_timeout = float(self.upload_io_timeout)
except Exception:
upload_io_timeout = 120.0
if upload_io_timeout <= 0:
upload_timeout = httpx.Timeout(
connect=float(self.timeout),
read=None,
write=None,
pool=float(self.timeout),
)
else:
upload_timeout = httpx.Timeout(
connect=float(self.timeout),
read=upload_io_timeout,
write=upload_io_timeout,
pool=float(self.timeout),
)
try:
chunk_size = int(self.upload_chunk_size)
except Exception:
chunk_size = 64 * 1024
if chunk_size <= 0:
chunk_size = 64 * 1024
# Stream upload body with a stderr progress bar (pipeline-safe).
from SYS.models import ProgressBar
@@ -198,7 +231,7 @@ class HydrusNetwork:
try:
with file_path.open("rb") as handle:
while True:
chunk = handle.read(256 * 1024)
chunk = handle.read(chunk_size)
if not chunk:
break
sent[0] += len(chunk)
@@ -216,6 +249,7 @@ class HydrusNetwork:
url,
content=file_gen(),
headers=headers,
timeout=upload_timeout,
raise_for_status=False,
log_http_errors=False,
)