Skip to content

Commit f69ce2d

Browse files
authored
Cleanup script - update timeout (#3387)
* draft of script * remove private repos * add cutoff to created repos * update check for maintainer * add warning for repos with critical amount of maintainers * include comments on issues as being active * add debug options, change to rest api to catch edge case * performance improvements * start script * create PR from results * improvements on grouping * add repos to ignore * use display name on readme PR * fix activity per team and not per user * add more ignore repos to the list * fix role check per repo * fix * update usage text * only run in a few repos for starters * add timeout and retry * dont retry on expected 404
1 parent 4a96694 commit f69ce2d

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

scripts/move-to-emeritus.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ def get_cutoff_date():
104104
cutoff = now - timedelta(days=INACTIVITY_MONTHS * 30)
105105
return cutoff.strftime("%Y-%m-%d")
106106

107-
def request_with_retry(method, url, data=None, retries=3):
107+
MAX_RATE_LIMIT_WAIT = 300 # cap waits at 5 min to avoid token expiry
108+
109+
def request_with_retry(method, url, data=None, retries=5):
108110
for attempt in range(1, retries + 1):
109111
req = urllib.request.Request(url, headers=HEADERS, method=method)
110112
if data is not None:
@@ -113,7 +115,7 @@ def request_with_retry(method, url, data=None, retries=3):
113115
else:
114116
body = None
115117
try:
116-
resp = urllib.request.urlopen(req, body)
118+
resp = urllib.request.urlopen(req, body, timeout=30)
117119
return resp
118120
except urllib.error.HTTPError as e:
119121
if e.code in (403, 429):
@@ -125,12 +127,24 @@ def request_with_retry(method, url, data=None, retries=3):
125127
wait = max(0, int(reset_time) - int(time.time())) + 1
126128
else:
127129
wait = 60
130+
wait = min(wait, MAX_RATE_LIMIT_WAIT)
128131
print(f"Rate limited. Waiting {wait}s before retry...")
129132
time.sleep(wait)
130133
continue
131-
print(f"Attempt {attempt} failed: HTTP {e.code}")
134+
if 500 <= e.code < 600:
135+
# Transient server error — retry with backoff
136+
print(f"Attempt {attempt} failed: HTTP {e.code}")
137+
if attempt < retries:
138+
time.sleep(2 ** attempt)
139+
else:
140+
raise
141+
continue
142+
# 4xx (other than 429/403): deterministic — don't retry
143+
raise
144+
except (TimeoutError, OSError) as e:
145+
print(f"Attempt {attempt} failed: {e}")
132146
if attempt < retries:
133-
time.sleep(1)
147+
time.sleep(2)
134148
else:
135149
raise
136150
return None

0 commit comments

Comments
 (0)