mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
GoogleSolarApiClient retries on transient HTTP errors 🟩
This commit is contained in:
parent
44217bf361
commit
497ef1faed
1 changed files with 15 additions and 5 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
from typing import Any, Literal
|
import time
|
||||||
|
from typing import Any, Literal, Optional
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
@ -28,7 +29,16 @@ class GoogleSolarApiClient:
|
||||||
"requiredQuality": required_quality,
|
"requiredQuality": required_quality,
|
||||||
"key": self._api_key,
|
"key": self._api_key,
|
||||||
}
|
}
|
||||||
response = requests.get(insights_url, params=params)
|
last_exc: Optional[Exception] = None
|
||||||
response.raise_for_status()
|
for attempt in range(self.MAX_RETRIES):
|
||||||
result: dict[str, Any] = response.json()
|
try:
|
||||||
return result
|
response = requests.get(insights_url, params=params)
|
||||||
|
response.raise_for_status()
|
||||||
|
result: dict[str, Any] = response.json()
|
||||||
|
return result
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
last_exc = e
|
||||||
|
time.sleep(2 ** attempt)
|
||||||
|
|
||||||
|
assert last_exc is not None
|
||||||
|
raise last_exc
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue