From c375a61b166845c2e55b841222d169b724e2e2e0 Mon Sep 17 00:00:00 2001 From: Nicolas Dandrimont Date: Thu, 25 Feb 2021 21:13:27 +0100 Subject: [PATCH] GitHub: handle Server Errors These errors happen, sometimes, when requesting large pages of results. --- swh/lister/github/lister.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/swh/lister/github/lister.py b/swh/lister/github/lister.py index b35ef9c..1d87676 100644 --- a/swh/lister/github/lister.py +++ b/swh/lister/github/lister.py @@ -13,7 +13,13 @@ from urllib.parse import parse_qs, urlparse import iso8601 import requests -from tenacity import retry, retry_any, retry_if_exception_type, wait_exponential +from tenacity import ( + retry, + retry_any, + retry_if_exception_type, + retry_if_result, + wait_exponential, +) from swh.scheduler.interface import SchedulerInterface from swh.scheduler.model import ListedOrigin @@ -65,6 +71,8 @@ class RateLimited(Exception): # ChunkedEncodingErrors happen when the TLS connection gets reset, e.g. # when running the lister on a connection with high latency retry_if_exception_type(requests.exceptions.ChunkedEncodingError), + # 502 status codes happen for a Server Error, sometimes + retry_if_result(lambda r: r.status_code == 502), ), ) def github_request(