PD migrator: retry on network errors (#1650)

This commit is contained in:
Vadim Stepanov 2023-03-28 16:57:37 +01:00 committed by GitHub
parent 63af99eb75
commit f83c5fca52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,7 @@ from urllib.parse import urljoin
import requests
from requests import HTTPError
from requests.adapters import HTTPAdapter, Retry
from migrator.config import ONCALL_API_TOKEN, ONCALL_API_URL
@ -11,7 +12,13 @@ from migrator.config import ONCALL_API_TOKEN, ONCALL_API_URL
def api_call(method: str, path: str, **kwargs) -> requests.Response:
url = urljoin(ONCALL_API_URL, path)
response = requests.request(
# Retry on network errors
session = requests.Session()
retries = Retry(total=5, backoff_factor=0.1)
session.mount("http://", HTTPAdapter(max_retries=retries))
session.mount("https://", HTTPAdapter(max_retries=retries))
response = session.request(
method, url, headers={"Authorization": ONCALL_API_TOKEN}, **kwargs
)