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

feat: make retry parameter public and added in other methods #331

Merged
merged 6 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 9 additions & 3 deletions google/cloud/storage/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ def reload(
blob's current metageneration does not match the given value.

:type retry: google.api_core.retry.Retry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically either google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy are supported here, and in some cases ConditionalRetryPolicy is the default so despite the complexity we should document it here.

:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.
Copy link
Contributor

@andrewsg andrewsg Dec 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Optional) How to retry the RPC. A None value will disable retries. A google.api_core.retry.Retry value will enable retries, and the object will define retriable response codes and errors and configure backoff and timeout options.

A google.cloud.storage.retry.ConditionalRetryPolicy value wraps a Retry object and activates it only if certain conditions are met. This class exists to provide safe defaults for RPC calls that are not technically safe to retry normally (due to potential data duplication or other side-effects) but become safe to retry if a condition such as if_metageneration_match is set.

See the retry.py source code and docstrings in this package (google.cloud.storage.retry) for information on retry types and how to configure them.

"""
client = self._require_client(client)
query_params = self._query_params
Expand Down Expand Up @@ -293,7 +295,9 @@ def patch(
blob's current metageneration does not match the given value.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.
"""
client = self._require_client(client)
query_params = self._query_params
Expand Down Expand Up @@ -371,7 +375,9 @@ def update(
blob's current metageneration does not match the given value.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.
"""
client = self._require_client(client)

Expand Down
20 changes: 15 additions & 5 deletions google/cloud/storage/acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,9 @@ def reload(self, client=None, timeout=_DEFAULT_TIMEOUT, retry=DEFAULT_RETRY):
See :meth:`requests.Session.request` documentation for details.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.
"""
path = self.reload_path
client = self._require_client(client)
Expand Down Expand Up @@ -495,7 +497,9 @@ def _save(
See :meth:`requests.Session.request` documentation for details.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.
"""
query_params = {"projection": "full"}
if predefined is not None:
Expand Down Expand Up @@ -544,7 +548,9 @@ def save(
See :meth:`requests.Session.request` documentation for details.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.
"""
if acl is None:
acl = self
Expand Down Expand Up @@ -581,7 +587,9 @@ def save_predefined(
See :meth:`requests.Session.request` documentation for details.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.
"""
predefined = self.validate_predefined(predefined)
self._save(None, predefined, client, timeout=timeout, retry=retry)
Expand All @@ -608,7 +616,9 @@ def clear(self, client=None, timeout=_DEFAULT_TIMEOUT, retry=DEFAULT_RETRY):
See :meth:`requests.Session.request` documentation for details.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.
"""
self.save([], client=client, timeout=timeout, retry=retry)

Expand Down
40 changes: 30 additions & 10 deletions google/cloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,9 @@ def exists(
current metageneration does not match the given value.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.

:rtype: bool
:returns: True if the blob exists in Cloud Storage.
Expand Down Expand Up @@ -727,7 +729,9 @@ def delete(
current metageneration does not match the given value.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.

:raises: :class:`google.cloud.exceptions.NotFound`
(propagated from
Expand Down Expand Up @@ -2732,7 +2736,9 @@ def get_iam_policy(
See :meth:`requests.Session.request` documentation for details.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.

:rtype: :class:`google.api_core.iam.Policy`
:returns: the policy instance, based on the resource returned from
Expand Down Expand Up @@ -2795,7 +2801,9 @@ def set_iam_policy(
See :meth:`requests.Session.request` documentation for details.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.

:rtype: :class:`google.api_core.iam.Policy`
:returns: the policy instance, based on the resource returned from
Expand Down Expand Up @@ -2854,7 +2862,9 @@ def test_iam_permissions(
See :meth:`requests.Session.request` documentation for details.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.

:rtype: list of string
:returns: the permissions returned by the ``testIamPermissions`` API
Expand Down Expand Up @@ -2886,7 +2896,9 @@ def make_public(self, client=None, retry=DEFAULT_RETRY):
to the ``client`` stored on the blob's bucket.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.
"""
self.acl.all().grant_read()
self.acl.save(client=client, retry=retry)
Expand All @@ -2900,7 +2912,9 @@ def make_private(self, client=None, retry=DEFAULT_RETRY):
to the ``client`` stored on the blob's bucket.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.
"""
self.acl.all().revoke_read()
self.acl.save(client=client, retry=retry)
Expand Down Expand Up @@ -2948,7 +2962,9 @@ def compose(
``sources`` item-to-item.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.

Example:
Compose blobs using generation match preconditions.
Expand Down Expand Up @@ -3112,7 +3128,9 @@ def rewrite(
object's current metageneration does not match the given value.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.

:rtype: tuple
:returns: ``(token, bytes_rewritten, total_bytes)``, where ``token``
Expand Down Expand Up @@ -3269,7 +3287,9 @@ def update_storage_class(
See :meth:`requests.Session.request` documentation for details.

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC.
:param retry: (Optional) How to retry the RPC. To modify the default retry behavior,
create a new retry object modeled after this one by calling it a ``with_XXX`` method.
See: https://googleapis.dev/python/google-api-core/latest/retry.html for details.
"""
if new_class not in self.STORAGE_CLASSES:
raise ValueError("Invalid storage class: %s" % (new_class,))
Expand Down
Loading