Skip to content

Commit

Permalink
add retry, part handling
Browse files Browse the repository at this point in the history
  • Loading branch information
aj-ya committed May 21, 2024
1 parent 3293104 commit a402ee3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
15 changes: 9 additions & 6 deletions outpostcli/lfs/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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}"
Expand Down
20 changes: 10 additions & 10 deletions outpostcli/lfs/storage_class/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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()
Expand Down

0 comments on commit a402ee3

Please sign in to comment.