Skip to content

Commit

Permalink
feat: retry and retry_async support streaming rpcs (#495)
Browse files Browse the repository at this point in the history
From #485:

> Server streaming libraries return an iterable that can asynchronously yield data from the backend over time. Some of our libraries need to provide a wrapper around the raw stream to do some local processing, before passing the data to the user.
>
> It would be useful to wrap this whole pipeline in a retry decorator, so that if the stream breaks mid-way through, we can recover and continue yielding data through our generator as if nothing happened.
>
> Unfortunately, the current implementation returns the result of the target function directly, so generators will not yield values and exceptions through the retry block

This PR addresses the issue by adding retry_target_generator functions to both the async and sync retry modules, which yield through the target rather than call it directly. Generator mode can be enabled using the is_generator argument on the decorator.

Fixes #485
---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <[email protected]>
Co-authored-by: Victor Chudnovsky <[email protected]>
  • Loading branch information
4 people authored Dec 12, 2023
1 parent 4d7d2ed commit 17ff5f1
Show file tree
Hide file tree
Showing 16 changed files with 2,891 additions and 1,106 deletions.
3 changes: 3 additions & 0 deletions google/api_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@
from google.api_core import version as api_core_version

__version__ = api_core_version.__version__

# for backwards compatibility, expose async unary retries as google.api_core.retry_async
from .retry import retry_unary_async as retry_async # noqa: F401
Loading

0 comments on commit 17ff5f1

Please sign in to comment.