mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +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
|
||||
|
||||
|
|
@ -28,7 +29,16 @@ class GoogleSolarApiClient:
|
|||
"requiredQuality": required_quality,
|
||||
"key": self._api_key,
|
||||
}
|
||||
response = requests.get(insights_url, params=params)
|
||||
response.raise_for_status()
|
||||
result: dict[str, Any] = response.json()
|
||||
return result
|
||||
last_exc: Optional[Exception] = None
|
||||
for attempt in range(self.MAX_RETRIES):
|
||||
try:
|
||||
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