Skip to content

Commit

Permalink
fix: complete
Browse files Browse the repository at this point in the history
  • Loading branch information
aj-ya committed May 21, 2024
1 parent 821ae3b commit cf9e8dc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
3 changes: 0 additions & 3 deletions outpostcli/lfs/storage_class/gcs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os
from math import ceil
from multiprocessing import cpu_count
from typing import Any, Dict, List, Literal, TypedDict

Expand All @@ -13,7 +11,6 @@
from outpostcli.lfs.storage_class.utils import (
abort_multipart_upload,
complete_multipart_upload,
initiate_multipart_upload,
)

_log = create_lfs_logger(__name__)
Expand Down
20 changes: 4 additions & 16 deletions outpostcli/lfs/storage_class/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,14 @@ def part_dict_list_to_xml(multi_parts: List[UploadedPartObject]):
wait=wait_exponential(multiplier=1, min=1, max=60), # Exponential backoff
)
def complete_multipart_upload(url: str, parts: List[UploadedPartObject]):
r = requests.post(url, data=part_dict_list_to_xml(parts))
r = requests.post(
url,
data=part_dict_list_to_xml(sorted(parts, key=lambda x: x.get("part_number"))), # type: ignore
)
r.raise_for_status()
return r


@handle_request_errors
@retry(
reraise=True,
stop=stop_after_attempt(4), # Maximum number of retries
wait=wait_exponential(multiplier=1, min=1, max=60), # Exponential backoff
)
def initiate_multipart_upload(url: str) -> str:
r = requests.post(url, headers={"Content-Type": "application/octet-stream"})
r.raise_for_status()
# parse uploadid from response example response
# <?xml version='1.0' encoding='UTF-8'?><InitiateMultipartUploadResult xmlns='http://s3.amazonaws.com/doc/2006-03-01/'><Bucket>pr-cache-bucket-0</Bucket><Key>randomfile.tar.gz</Key><UploadId>ABPnzm5hfCDjy44Aa2WDHPxGL9kDyJ3GwtFvToGhVYgNul2PiIOcGI8siu_HjXHeYRkbPxo</UploadId></InitiateMultipartUploadResult>
upload_id = r.text.split("<UploadId>")[1].split("</UploadId>")[0]
return upload_id


@handle_request_errors
@retry(
reraise=True,
Expand Down

0 comments on commit cf9e8dc

Please sign in to comment.