Skip to content

Commit

Permalink
Infra: introduce retry func warpper
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghua committed Sep 12, 2024
1 parent 904c982 commit 44035aa
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions tosfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,15 +695,33 @@ def put_file(
content=chunk,
content_type=content_type,
)
retryable_func(
lambda: self.tos_client.put_object(
bucket,
key,
content=chunk,
content_type=content_type,
),
max_retry_num=self.max_retry_num,
)
else:
mpu = self.tos_client.create_multipart_upload(
bucket, key, content_type=content_type
mpu = retryable_func(
lambda: self.tos_client.create_multipart_upload(
bucket, key, content_type=content_type
),
max_retry_num=self.max_retry_num,
)
self.tos_client.upload_part_from_file(
bucket, key, mpu.upload_id, file_path=lpath, part_number=1
retryable_func(
lambda: self.tos_client.upload_part_from_file(
bucket, key, mpu.upload_id, file_path=lpath, part_number=1
),
max_retry_num=self.max_retry_num,
)
self.tos_client.complete_multipart_upload(
bucket, key, mpu.upload_id, complete_all=True
retryable_func(
lambda: self.tos_client.complete_multipart_upload(
bucket, key, mpu.upload_id, complete_all=True
),
max_retry_num=self.max_retry_num,
)
except (TosClientError, TosServerError) as e:
raise e
Expand Down

0 comments on commit 44035aa

Please sign in to comment.