Skip to content

Commit f1d06a7

Browse files
authored
Use stamina to retry on HTTP 5xx errors (#34)
1 parent d23ed91 commit f1d06a7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

potential_closeable_issues.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# dependencies = [
99
# "ghapi",
1010
# "rich",
11+
# "stamina",
1112
# ]
1213
# ///
1314

@@ -18,7 +19,9 @@
1819
import json
1920
import os
2021
from typing import Any, TypeAlias
22+
from urllib.error import HTTPError
2123

24+
import stamina
2225
from fastcore.net import HTTP404NotFoundError
2326
from fastcore.xtras import obj2dict
2427
from ghapi.all import GhApi, paged # pip install ghapi
@@ -68,7 +71,9 @@ def check_issue(api: GhApi, issue: Issue) -> list[Issue]:
6871
word = next(word for word in pr_line.split() if word.startswith("gh-"))
6972
pr_number = int(word.split("-")[1])
7073
try:
71-
pr = api.pulls.get(pr_number)
74+
for attempt in stamina.retry_context(on=HTTPError):
75+
with attempt:
76+
pr = api.pulls.get(pr_number)
7277
except HTTP404NotFoundError as e:
7378
print(f"[yellow]PR {pr_number} not found: {e}[/yellow]")
7479
continue

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ pytest
1010
pytest-cov
1111
requests
1212
rich
13+
stamina
1314
termcolor

0 commit comments

Comments
 (0)