Skip to content

Commit

Permalink
add retry to gcs.upload_file (mosaicml#3232)
Browse files Browse the repository at this point in the history
* add retry to gcs.upload_file

* fix unit test
  • Loading branch information
bigning authored May 7, 2024
1 parent ce782b3 commit 9538777
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer/utils/object_store/gcs_object_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,12 @@ def upload_object(

if callback is not None:
raise ValueError('callback is not supported in gcs upload_object()')
from google.cloud.storage.retry import DEFAULT_RETRY
src = filename
dest = object_name
dest = str(src) if dest == '' else dest
blob = self.bucket.blob(self.get_key(dest))
blob.upload_from_filename(src)
blob.upload_from_filename(src, retry=DEFAULT_RETRY) # pyright: ignore[reportGeneralTypeIssues]

def download_object(
self,
Expand Down
3 changes: 2 additions & 1 deletion tests/utils/object_store/test_gs_object_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def test_upload_object(gs_object_store, monkeypatch):

gs_object_store.upload_object(destination_blob_name, source_file_name)

mock_blob.upload_from_filename.assert_called_with(source_file_name)
from google.cloud.storage.retry import DEFAULT_RETRY
mock_blob.upload_from_filename.assert_called_with(source_file_name, retry=DEFAULT_RETRY)
assert mock_blob.upload_from_filename.call_count == 1


Expand Down

0 comments on commit 9538777

Please sign in to comment.