Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cloud): Retry on all failures #165

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions streamer/proxy_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
# Optional: To support S3, import AWS's boto3 library.
try:
import boto3 # type: ignore
import botocore.config # type: ignore
SUPPORTED_PROTOCOLS.append('s3')
except:
pass
Expand Down Expand Up @@ -231,15 +232,17 @@ def handle_non_chunked(self, path: str, length: int,
blob.cache_control = 'no-cache'

# If you don't pass size=length, it tries to seek in the file, which fails.
blob.upload_from_file(file, size=length, retries=3)
blob.upload_from_file(file, size=length,
retry=google.cloud.storage.retry.DEFAULT_RETRY)

def start_chunked(self, path: str) -> None:
# No leading slashes, or we get a blank folder name.
full_path = (self._base_path + path).strip('/')
blob = self._bucket.blob(full_path)
blob.cache_control = 'no-cache'

self._chunked_output = blob.open('wb')
self._chunked_output = blob.open(
'wb', retry=google.cloud.storage.retry.DEFAULT_RETRY)

def handle_chunk(self, data: bytes) -> None:
assert self._chunked_output is not None
Expand All @@ -255,7 +258,7 @@ def handle_delete(self, path: str) -> None:
full_path = (self._base_path + path).strip('/')
blob = self._bucket.blob(full_path)
try:
blob.delete()
blob.delete(retry=google.cloud.storage.retry.DEFAULT_RETRY)
except google.api_core.exceptions.NotFound:
# Some delete calls seem to throw "not found", but the files still get
# deleted. So ignore these and don't fail the request.
Expand All @@ -266,7 +269,7 @@ class S3Handler(RequestHandlerBase):
# Can't annotate the client here as a parameter if we don't have the library.
def __init__(self, client: Any, bucket_name: str, base_path: str,
rate_limiter: RateLimiter, *args, **kwargs) -> None:
self._client: boto3.Client = client
self._client: boto3.client = client
self._bucket_name: str = bucket_name
self._base_path: str = base_path

Expand Down Expand Up @@ -432,7 +435,8 @@ def __init__(self, upload_location: str) -> None:
super().__init__()

url = urllib.parse.urlparse(upload_location)
self._client = boto3.client('s3')
config = botocore.config.Config(retries = {'mode': 'standard'})
self._client = boto3.client('s3', config=config)
self._bucket_name = url.netloc
# Strip both left and right slashes. Otherwise, we get a blank folder name.
self._base_path = url.path.strip('/')
Expand Down