power: add retries to http requests
This is an attempt to mitigate 599 errors raised by tornado's curl based http client. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
1cac7399f9
commit
7fcd84bbe4
|
@ -416,15 +416,20 @@ class HTTPDevice(PowerDevice):
|
|||
|
||||
async def _send_http_command(self,
|
||||
url: str,
|
||||
command: str
|
||||
command: str,
|
||||
retries: int = 3
|
||||
) -> Dict[str, Any]:
|
||||
for i in range(retries):
|
||||
try:
|
||||
response = await self.client.fetch(url)
|
||||
response = await self.client.fetch(
|
||||
url, connect_timeout=5., request_timeout=20.)
|
||||
data = json_decode(response.body)
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
if i == retries - 1:
|
||||
msg = f"Error sending '{self.type}' command: {command}"
|
||||
logging.exception(msg)
|
||||
raise self.server.error(msg)
|
||||
raise self.server.error(msg) from e
|
||||
else:
|
||||
break
|
||||
return data
|
||||
|
||||
async def _send_power_request(self, state: str) -> str:
|
||||
|
|
Loading…
Reference in New Issue