diff --git a/outpostcli/lfs/part.py b/outpostcli/lfs/part.py index be9a5b1..c8e9068 100644 --- a/outpostcli/lfs/part.py +++ b/outpostcli/lfs/part.py @@ -5,7 +5,7 @@ from outpostkit.repository.lfs.logger import create_lfs_logger from tenacity import before_sleep_log, retry, stop_after_attempt, wait_exponential -from outpostcli.lfs.exc import ProxyLFSException, handle_request_errors +from outpostcli.lfs.exc import LFSException, ProxyLFSException, handle_request_errors from outpostcli.lfs.file_slice import FileSlice from outpostcli.lfs.parallel import map_wrap from outpostcli.lfs.types import UploadedPartObject @@ -22,11 +22,12 @@ class PartInfo: @handle_request_errors("UploadPart") -# @retry( -# stop=stop_after_attempt(4), # Maximum number of retries -# wait=wait_exponential(multiplier=1, min=4, max=60), # Exponential backoff -# before_sleep=before_sleep_log(_log, logging.INFO, exc_info=True), -# ) +@retry( + reraise=True, + stop=stop_after_attempt(4), # Maximum number of retries + wait=wait_exponential(multiplier=1, min=4, max=60), # Exponential backoff + before_sleep=before_sleep_log(_log, logging.INFO, exc_info=True), +) def retriable_upload_part(url: str, data: FileSlice): r = requests.put(url, data=data) r.raise_for_status() @@ -43,6 +44,8 @@ def transfer_part(part: PartInfo): try: _log.info(f"uploading part of {part.filepath}, part no: {part.no}") r = retriable_upload_part(part.url, data) + if isinstance(r, LFSException): + raise LFSException(code=r.code, message=r.message, doc_url=r.doc_url) etag = str(r.headers.get("etag")) _log.info( f"completed upload part of {part.filepath}, part no: {part.no}, etag: {etag}" diff --git a/outpostcli/lfs/storage_class/utils.py b/outpostcli/lfs/storage_class/utils.py index 811619c..9b0a267 100644 --- a/outpostcli/lfs/storage_class/utils.py +++ b/outpostcli/lfs/storage_class/utils.py @@ -31,12 +31,12 @@ def part_dict_list_to_xml(multi_parts: List[UploadedPartObject]): return s -# @retry( -# reraise=True, -# stop=stop_after_attempt(4), # Maximum number of retries -# wait=wait_exponential(multiplier=1, min=1, max=60), # Exponential backoff -# ) @handle_request_errors(prefix="CompleteMultipartUpload") +@retry( + reraise=True, + stop=stop_after_attempt(4), # Maximum number of retries + wait=wait_exponential(multiplier=1, min=1, max=60), # Exponential backoff +) def complete_multipart_upload(url: str, parts: List[UploadedPartObject]): data = part_dict_list_to_xml(sorted(parts, key=lambda x: x.get("part_number"))) _log.info({"completion_url": url, "data": data}) @@ -50,11 +50,11 @@ def complete_multipart_upload(url: str, parts: List[UploadedPartObject]): @handle_request_errors(prefix="AbortMultipartUpload") -# @retry( -# reraise=True, -# stop=stop_after_attempt(4), # Maximum number of retries -# wait=wait_exponential(multiplier=1, min=1, max=60), # Exponential backoff -# ) +@retry( + reraise=True, + stop=stop_after_attempt(4), # Maximum number of retries + wait=wait_exponential(multiplier=1, min=1, max=60), # Exponential backoff +) def abort_multipart_upload(url: str): r = requests.delete(url) r.raise_for_status()