Skip to content

Commit a8c6ae0

Browse files
committed
Replacing backoff with tenacity.
1 parent 1327987 commit a8c6ae0

File tree

6 files changed

+46
-32
lines changed

6 files changed

+46
-32
lines changed

docker-health-check/docker_health_check/api/healthcheck.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
from typing import TYPE_CHECKING, Any
66

77
import anyio
8-
import backoff
98
import requests
109
from docker.client import DockerClient
1110
from tabulate import tabulate
11+
from tenacity import (
12+
retry,
13+
retry_if_exception,
14+
stop_after_attempt,
15+
wait_exponential,
16+
)
1217

1318
from docker_health_check import __version__, constants, utils
1419
from docker_health_check.models import ContainerRow
@@ -34,7 +39,11 @@ async def _restart(state: tuple[ContainerRow, NotificationHub]) -> None:
3439
notification_hub.enqueue(message)
3540

3641

37-
@backoff.on_exception(backoff.expo, requests.exceptions.RequestException, max_tries=constants.MAX_RETRY)
42+
@retry(
43+
retry=retry_if_exception(lambda ex: isinstance(ex, requests.exceptions.RequestException)),
44+
wait=wait_exponential(),
45+
stop=stop_after_attempt(constants.MAX_RETRY),
46+
)
3847
def _get_containers(client: DockerClient, filters: dict[str, Any] | None) -> Iterable[ContainerRow]:
3948
containers = client.containers.list(filters=filters)
4049
return map(ContainerRow.from_container, containers)

docker-health-check/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ dependencies = [
2727
"tabulate<1.0.0,>=0.9.0",
2828
"pydantic<3.0.0,>=2.9.2",
2929
"pydantic-settings<3.0.0,>=2.6.0",
30-
"backoff<3.0.0,>=2.2.1",
30+
"tenacity>=9.1.2",
3131
]
3232

3333
[dependency-groups]

docker-health-check/uv.lock

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

github/github/httpclient.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
from http import HTTPMethod, HTTPStatus
77
from typing import TYPE_CHECKING, Any, Final, Self, cast
88

9-
import backoff
109
from curl_cffi import requests
10+
from tenacity import (
11+
retry,
12+
retry_if_exception,
13+
stop_after_attempt,
14+
stop_after_delay,
15+
wait_exponential,
16+
)
1117

1218
from github import constants
1319

@@ -68,11 +74,10 @@ async def _execute(
6874
async with self._make_request(method, url, headers, params=params) as response:
6975
assert response.status_code == HTTPStatus.NO_CONTENT
7076

71-
@backoff.on_exception(
72-
backoff.expo,
73-
requests.exceptions.RequestException,
74-
max_tries=constants.MAX_RETRIES,
75-
max_time=constants.MAX_RETRY_TIME,
77+
@retry(
78+
retry=retry_if_exception(lambda ex: isinstance(ex, requests.exceptions.RequestException)),
79+
wait=wait_exponential(),
80+
stop=stop_after_attempt(constants.MAX_RETRIES) | stop_after_delay(constants.MAX_RETRY_TIME),
7681
)
7782
@asynccontextmanager
7883
async def _make_request(

github/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ classifiers = [
2222
requires-python = "<4.0,>=3.14"
2323
dependencies = [
2424
"asyncclick<9.0.0.0,>=8.1.7.2",
25-
"backoff<3.0.0,>=2.2.1",
25+
"tenacity>=9.1.2",
2626
"pyjwt<3.0.0,>=2.9.0",
2727
"cryptography<45.0.0,>=44.0.0",
2828
"curl-cffi>=0.13.0",

github/uv.lock

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

0 commit comments

Comments
 (0)