Skip to content
Snippets Groups Projects
Unverified Commit 185b6ce3 authored by Andrej Shadura's avatar Andrej Shadura
Browse files

Use structlog in chunked client


Signed-off-by: default avatarAndrej Shadura <andrew.shadura@collabora.co.uk>
parent e474c661
No related branches found
No related tags found
No related merge requests found
Pipeline #585887 failed
......@@ -11,13 +11,15 @@
import hashlib
from dataclasses import dataclass
from logging import debug
import structlog
import httpx
from aiofiles.threadpool import AsyncFileIO
from werkzeug.datastructures import ContentRange
from werkzeug.http import unquote_etag
logger = structlog.get_logger()
UPLOAD_CHUNK_SIZE = 512 * 1024 * 1024
MAX_ATTEMPTS = 5
......@@ -78,28 +80,31 @@ async def upload_chunked(
exc = None
for attempt in range(MAX_ATTEMPTS):
try:
debug(f"patching {uri} ({len(chunk)} {content_range})")
logger.debug("patching", uri=uri, size=len(chunk), content_range=content_range, attempt=attempt))
r = await client.patch(
uri,
content=chunk,
headers=chunk_headers,
**kv,
)
logger.debug("patch result", result=r)
if r.is_success:
break
else:
r.raise_for_status()
except httpx.HTTPStatusError as e:
if not e.response.is_server_error:
logger.debug("not server error, not retrying", resp=e.response)
raise
debug(f"retrying ({attempt})")
logger.exception("retrying", attempt=attempt)
exc = e
except httpx.HTTPError as e:
debug(f"retrying ({attempt})")
logger.exception("retrying", attempt=attempt)
exc = e
else:
raise exc
logger.debug("get etag", uri=uri)
# now verify the hash
r = await client.head(
uri,
......@@ -108,7 +113,7 @@ async def upload_chunked(
calculated_hash = file_hasher.hexdigest()
etag, _ = unquote_etag(r.headers.get("etag"))
debug("f{etag = } vs {calculated_hash = }")
logger.debug("check upload", etag=etag, calculated_hash=calculated_hash)
if etag != calculated_hash:
raise ChunkedUploadVerificationError(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment