diff --git a/backend/image_transfer/encoder.py b/backend/image_transfer/encoder.py index 9977ddae9..1718e1a4f 100644 --- a/backend/image_transfer/encoder.py +++ b/backend/image_transfer/encoder.py @@ -7,10 +7,10 @@ from typing import Optional from typing import Union +import structlog from dxf import DXF from dxf import DXFBase from requests import HTTPError -from tqdm import tqdm from image_transfer.common import Authenticator from image_transfer.common import Blob @@ -23,6 +23,8 @@ from substrapp.docker_registry import RegistryPreconditionFailedException from substrapp.utils import safezip +logger = structlog.get_logger("worker") + def add_blobs_to_zip( dxf_base: DXFBase, @@ -58,15 +60,23 @@ def add_blobs_to_zip( def download_blob_to_zip(dxf_base: DXFBase, blob: Blob, zip_file: safezip.ZipFile): repository_dxf = DXF.from_base(dxf_base, blob.repository) - bytes_iterator, total_size = repository_dxf.pull_blob(blob.digest, size=True) + try: + bytes_iterator, total_size = repository_dxf.pull_blob(blob.digest, size=True) + except Exception as e: + logger.exception(f"Failed to download blob {blob}", e=e) + raise e # we write the blob directly to the zip file - with tqdm(total=total_size, unit="B", unit_scale=True) as pbar: - blob_path_in_zip = f"blobs/{blob.digest}" + blob_path_in_zip = f"blobs/{blob.digest}" + try: with zip_file.open(blob_path_in_zip, "w", force_zip64=True) as blob_in_zip: for chunk in bytes_iterator: blob_in_zip.write(chunk) - pbar.update(len(chunk)) + except Exception as e: + logger.exception(f"Failed to write blob {blob} to zip file", e=e) + raise e + + logger.info(f"Blob {blob} of size {total_size} downloaded and stored in zip file") return blob_path_in_zip diff --git a/backend/requirements.txt b/backend/requirements.txt index 3b8a16c18..c5ab6e394 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -24,7 +24,6 @@ django-filter==24.2 pydantic==2.4.0 redis==5.0.0 mozilla-django-oidc==4.0.1 -tqdm==4.66.4 python-dxf==12.1.0 watchdog==2.1.9 # Prevent error linked to Deprecation warnings diff --git a/changes/990.removed b/changes/990.removed new file mode 100644 index 000000000..86af537ad --- /dev/null +++ b/changes/990.removed @@ -0,0 +1 @@ +`tqdm` dependency, only used in logging