Skip to content

Commit 75ac926

Browse files
authored
refactor(retry): migrate from backoff to tenacity (#1000)
1 parent 84eda92 commit 75ac926

File tree

24 files changed

+1262
-1112
lines changed

24 files changed

+1262
-1112
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ repos:
9696
# `types-$lib` or `$lib-stubs`.
9797
additional_dependencies:
9898
- aiohttp==3.13.3
99-
- backoff==2.2.1
10099
- cryptography==46.0.6
101100
- pyjwt==2.12.1
101+
- tenacity==9.1.2
102102
- types-requests==2.32.4.20260324
103103
args:
104104
- --show-error-codes

auth/gcloud/aio/auth/token.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
from urllib.parse import urlencode
1818
from urllib.parse import urlparse
1919

20-
import backoff
2120
import cryptography # pylint: disable=unused-import
2221
import jwt
22+
from tenacity import retry
23+
from tenacity import retry_if_exception_type
24+
from tenacity import stop_after_attempt
25+
from tenacity import wait_random_exponential
2326

2427
from .build_constants import BUILD_GCLOUD_REST
2528
from .session import AioSession
@@ -276,7 +279,12 @@ async def ensure_token(self) -> None:
276279
async def refresh(self, *, timeout: int) -> TokenResponse:
277280
pass
278281

279-
@backoff.on_exception(backoff.expo, Exception, max_tries=5)
282+
@retry(
283+
retry=retry_if_exception_type(Exception),
284+
stop=stop_after_attempt(5),
285+
wait=wait_random_exponential(multiplier=1, max=60),
286+
reraise=True,
287+
)
280288
async def acquire_access_token(self, timeout: int = 10) -> None:
281289
resp = await self.refresh(timeout=timeout)
282290

auth/poetry.lock

Lines changed: 21 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auth/poetry.rest.lock

Lines changed: 161 additions & 137 deletions
Large diffs are not rendered by default.

auth/pyproject.rest.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ classifiers = [
2222
[tool.poetry.dependencies]
2323
python = ">= 3.10, < 4.0"
2424
# aiohttp = ">= 3.9.2, < 4.0.0"
25-
backoff = ">= 1.0.0, < 3.0.0"
26-
chardet = ">= 2.0, < 7.0"
25+
chardet = ">= 2.0, < 6.0"
2726
# See https://cryptography.io/en/latest/api-stability/#deprecation
2827
cryptography = ">= 2.0.0, < 49.0.0" # pin max to < (major + 3)
2928
pyjwt = ">= 1.5.3, < 3.0.0"
3029
requests = ">= 2.2.1, < 3.0.0"
30+
tenacity = ">= 8.2.0, < 10.0.0"
3131

3232
[tool.poetry.group.dev.dependencies]
3333
pytest = "9.0.2"

auth/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ classifiers = [
2222
[tool.poetry.dependencies]
2323
python = ">= 3.10, < 4.0"
2424
aiohttp = ">= 3.9.2, < 4.0.0"
25-
backoff = ">= 1.0.0, < 3.0.0"
26-
chardet = ">= 2.0, < 7.0"
25+
chardet = ">= 2.0, < 6.0"
2726
# See https://cryptography.io/en/latest/api-stability/#deprecation
2827
cryptography = ">= 2.0.0, < 49.0.0" # pin max to < (major + 3)
2928
pyjwt = ">= 1.5.3, < 3.0.0"
3029
# requests = ">= 2.2.1, < 3.0.0"
30+
tenacity = ">= 8.2.0, < 10.0.0"
3131

3232
[tool.poetry.group.dev.dependencies]
3333
pytest = "9.0.2"

0 commit comments

Comments
 (0)