make ePIC api calls more reliable

This commit is contained in:
John-Paul Compagnone
2024-02-10 21:59:08 -05:00
parent ce288e472f
commit ab0dcd607b
2 changed files with 41 additions and 35 deletions

View File

@@ -939,11 +939,14 @@ class MinerFactory:
pass
async def get_miner_model_epic(self, ip: str) -> str | None:
for retry_cnt in range(settings.get("get_data_retries", 1)):
sock_json_data = await self.send_web_command(ip, ":4028/capabilities")
try:
miner_model = sock_json_data["Model"]
return miner_model
except (TypeError, LookupError):
if retry_cnt < settings.get("get_data_retries", 1) - 1:
continue
pass
async def get_miner_model_hiveon(self, ip: str) -> str | None:

View File

@@ -44,6 +44,7 @@ class ePICWebAPI(BaseWebAPI):
post = privileged or not parameters == {}
async with httpx.AsyncClient(transport=settings.transport()) as client:
for retry_cnt in range(settings.get("get_data_retries", 1)):
try:
if post:
response = await client.post(
@@ -69,6 +70,8 @@ class ePICWebAPI(BaseWebAPI):
if json_data:
# The API can return a fail status if the miner cannot return the requested data. Catch this and pass
if not json_data.get("result", True) and not post:
if retry_cnt < settings.get("get_data_retries", 1) - 1:
continue
if not ignore_errors:
raise APIError(json_data["error"])
return json_data