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

Use custom download chunk size and increase download resume attempts #479

Merged
merged 1 commit into from
Jul 2, 2019
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
7 changes: 6 additions & 1 deletion pipe-cli/src/utilities/storage/gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from google.auth.transport.requests import AuthorizedSession
from google.cloud.storage import Client, Blob
from google.oauth2.credentials import Credentials
from google import resumable_media
from google.resumable_media import DataCorruption
from google.resumable_media.requests import Download

Expand Down Expand Up @@ -169,7 +170,7 @@ def _do_resumable_upload(self, client, stream, content_type, size, num_retries,

class _ProgressBlob(_ResumableDownloadProgressMixin, _UploadProgressMixin, Blob):
PROGRESS_CHUNK_SIZE = 5 * 1024 * 1024 # 5 MB
DEFAULT_RESUME_ATTEMPTS = 5
DEFAULT_RESUME_ATTEMPTS = 100

def __init__(self, size, progress_callback, attempts=DEFAULT_RESUME_ATTEMPTS, *args, **kwargs):
"""
Expand Down Expand Up @@ -490,12 +491,16 @@ def transfer(self, source_wrapper, destination_wrapper, path=None, relative_path

def _download_to_file(self, blob, destination_key):
try:
self._replace_default_download_chunk_size(self._buffering)
with open(destination_key, "wb", buffering=self._buffering) as file_obj:
blob.download_to_file(file_obj)
except DataCorruption:
os.remove(destination_key)
raise

def _replace_default_download_chunk_size(self, chunk_size):
resumable_media.requests.download._SINGLE_GET_CHUNK_SIZE = chunk_size


class GsUploadManager(GsManager, AbstractTransferManager):

Expand Down