Retry and Timeout Changes for espminer (#340)

* Retry and Timeout Fixes for espminer

* Build check fix
This commit is contained in:
Ryan Heideman
2025-05-01 14:07:58 -07:00
committed by GitHub
parent b8ae238d23
commit 40ebc2773f

View File

@@ -20,34 +20,36 @@ class ESPMinerWebAPI(BaseWebAPI):
**parameters: Any, **parameters: Any,
) -> dict: ) -> dict:
url = f"http://{self.ip}:{self.port}/api/{command}" url = f"http://{self.ip}:{self.port}/api/{command}"
try: async with httpx.AsyncClient(transport=settings.transport()) as client:
async with httpx.AsyncClient( for _ in range(settings.get("get_data_retries", 1)):
transport=settings.transport(),
) as client:
if parameters.get("post", False):
parameters.pop("post")
data = await client.post(
url,
timeout=settings.get("api_function_timeout", 3),
json=parameters,
)
elif parameters.get("patch", False):
parameters.pop("patch")
data = await client.patch(
url,
timeout=settings.get("api_function_timeout", 3),
json=parameters,
)
else:
data = await client.get(url)
except httpx.HTTPError:
pass
else:
if data.status_code == 200:
try: try:
return data.json() if parameters.get("post", False):
except json.decoder.JSONDecodeError: parameters.pop("post")
data = await client.post(
url,
timeout=settings.get("api_function_timeout", 3),
json=parameters,
)
elif parameters.get("patch", False):
parameters.pop("patch")
data = await client.patch(
url,
timeout=settings.get("api_function_timeout", 3),
json=parameters,
)
else:
data = await client.get(
url,
timeout=settings.get("api_function_timeout", 5),
)
except httpx.HTTPError:
pass pass
else:
if data.status_code == 200:
try:
return data.json()
except json.decoder.JSONDecodeError:
pass
async def multicommand( async def multicommand(
self, *commands: str, ignore_errors: bool = False, allow_warning: bool = True self, *commands: str, ignore_errors: bool = False, allow_warning: bool = True