我使用的是python的elasticsearch dsl库。我在一个线程应用程序中运行滚动扫描,如下所示:
s = Search\
.from_dict(query)\
.using(es)\
.index(index)\
.doc_type(doc_type)\
.extra(slice=slice)
for hit in s.scan():
yield hit可以有32个线程全部运行在具有不同切片的同一滚动条上。有时,这会导致429 Too Many Requests错误,并终止整个过程。令人心碎的是,这可能会在滚动1小时后发生,这个过程只需要重新开始。
我如何恢复一个429太多的请求错误?是否可以在不重新启动整个滚动的情况下,在最后一个滚动偏移处重试?
发布于 2021-07-31 08:01:57
使用retry库。我有一个自定义的TooManyRequestsError,只捕获429个
@retry(TooManyRequestsError, delay=3, jitter=3, max_delay=30)
def get(url: str) -> requests.Response:
res = requests.get(url)
if res.status_code == 429:
logger.warning(f'Too many requests! {url}')
raise TooManyRequestsError()
res.raise_for_status()
return reshttps://stackoverflow.com/questions/68456825
复制相似问题