Skip to content

Commit 566ce13

Browse files
committed
ci: Create constants for retry mechanism variables
1 parent de2376c commit 566ce13

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

dependencies/scripts/download_packages.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,23 @@
1919
)
2020

2121

22+
class ServerError(Exception):
23+
"""Custom exception for HTTP 5xx errors."""
24+
25+
26+
# Directory name
2227
DEPENDENCIES_DIR = "dependencies"
28+
29+
# Sources
2330
TOP_PYPI_SOURCE = "https://hugovk.github.io/top-pypi-packages/top-pypi-packages.min.json"
2431
TOP_NPM_SOURCE = "https://packages.ecosyste.ms/api/v1/registries/npmjs.org/packages"
32+
33+
# Retry configuration constants
34+
RETRY_EXCEPTIONS = (httpx.TransportError, httpx.TimeoutException, ServerError)
35+
RETRY_ATTEMPTS = 10
36+
RETRY_WAIT_JITTER = 1
37+
RETRY_WAIT_EXP_BASE = 2
38+
RETRY_WAIT_MAX = 8
2539
TIMEOUT = 90
2640

2741

@@ -33,10 +47,6 @@ def parse_pypi(data: dict[str, Any]) -> set[str]:
3347
return {row["project"] for row in data["rows"]}
3448

3549

36-
class ServerError(Exception):
37-
"""Custom exception for HTTP 5xx errors."""
38-
39-
4050
@dataclass(frozen=True)
4151
class Ecosystem:
4252
url: str
@@ -94,11 +104,11 @@ def download(
94104

95105

96106
@stamina.retry(
97-
on=(httpx.TransportError, httpx.TimeoutException, ServerError),
98-
attempts=10,
99-
wait_jitter=1,
100-
wait_exp_base=2,
101-
wait_max=8,
107+
on=RETRY_EXCEPTIONS,
108+
attempts=RETRY_ATTEMPTS,
109+
wait_jitter=RETRY_WAIT_JITTER,
110+
wait_exp_base=RETRY_WAIT_EXP_BASE,
111+
wait_max=RETRY_WAIT_MAX,
102112
)
103113
def get_packages(
104114
base_url: str, parser: Callable[[dict[str, Any]], set[str]], params: dict[str, Any] | None = None

0 commit comments

Comments
 (0)