Skip to content

Commit 8708aa9

Browse files
committed
add retry parameter (urllib3.util.retry.Retry object) to retry (with exponential backoff) on server error
1 parent a8d4c2b commit 8708aa9

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

ccos/gh_utils.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Third-party
88
from github import Github
99
from github.GithubException import BadCredentialsException
10+
from urllib3.util.retry import Retry
1011

1112
GITHUB_ORGANIZATION = "creativecommons"
1213
GITHUB_USERNAME_DEFAULT = "cc-creativecommons-github-io-bot"
@@ -29,7 +30,26 @@ def get_credentials():
2930
def set_up_github_client():
3031
_, github_token = get_credentials()
3132
LOG.info("Setting up GitHub client...")
32-
github_client = Github(github_token)
33+
# TODO: Remove retry parameter (urllib3.util.retry.Retry object) once we
34+
# are using PyGithub v2.0
35+
# https://github.com/creativecommons/ccos-scripts/issues/179
36+
retry = Retry(
37+
# try again after 5, 10, 20, 40, 80 seconds
38+
# for specified HTTP status codes
39+
total=5,
40+
backoff_factor=10,
41+
status_forcelist=list(range(500, 600)),
42+
allowed_methods={
43+
"DELETE",
44+
"GET",
45+
"HEAD",
46+
"OPTIONS",
47+
"POST",
48+
"PUT",
49+
"TRACE",
50+
},
51+
)
52+
github_client = Github(login_or_token=github_token, retry=retry)
3353
LOG.success("done.")
3454
return github_client
3555

0 commit comments

Comments
 (0)