From 92a705f8fd51eff00ca57936e12b792bc1b4a53b Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 9 Jan 2023 13:11:22 +0530 Subject: [PATCH] ci: retry if rate limited in roulette (#19523) [skip ci] --- .github/helper/roulette.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/helper/roulette.py b/.github/helper/roulette.py index 9eec32e863..f2a8bcb700 100644 --- a/.github/helper/roulette.py +++ b/.github/helper/roulette.py @@ -4,8 +4,10 @@ import re import shlex import subprocess import sys +import time import urllib.request from functools import lru_cache +from urllib.error import HTTPError @lru_cache(maxsize=None) @@ -15,11 +17,25 @@ def fetch_pr_data(pr_number, repo, endpoint=""): if endpoint: api_url += f"/{endpoint}" - req = urllib.request.Request(api_url) - res = urllib.request.urlopen(req) + res = req(api_url) return json.loads(res.read().decode("utf8")) +def req(url): + "Simple resilient request call to handle rate limits." + retries = 0 + while True: + try: + req = urllib.request.Request(url) + return urllib.request.urlopen(req) + except HTTPError as exc: + if exc.code == 403 and retries < 5: + retries += 1 + time.sleep(retries) + continue + raise + + def get_files_list(pr_number, repo="frappe/frappe"): return [change["filename"] for change in fetch_pr_data(pr_number, repo, "files")]