make ePIC api calls more reliable
This commit is contained in:
@@ -939,12 +939,15 @@ class MinerFactory:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
async def get_miner_model_epic(self, ip: str) -> str | None:
|
async def get_miner_model_epic(self, ip: str) -> str | None:
|
||||||
sock_json_data = await self.send_web_command(ip, ":4028/capabilities")
|
for retry_cnt in range(settings.get("get_data_retries", 1)):
|
||||||
try:
|
sock_json_data = await self.send_web_command(ip, ":4028/capabilities")
|
||||||
miner_model = sock_json_data["Model"]
|
try:
|
||||||
return miner_model
|
miner_model = sock_json_data["Model"]
|
||||||
except (TypeError, LookupError):
|
return miner_model
|
||||||
pass
|
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:
|
async def get_miner_model_hiveon(self, ip: str) -> str | None:
|
||||||
sock_json_data = await self.send_api_command(ip, "version")
|
sock_json_data = await self.send_api_command(ip, "version")
|
||||||
|
|||||||
@@ -44,37 +44,40 @@ class ePICWebAPI(BaseWebAPI):
|
|||||||
post = privileged or not parameters == {}
|
post = privileged or not parameters == {}
|
||||||
|
|
||||||
async with httpx.AsyncClient(transport=settings.transport()) as client:
|
async with httpx.AsyncClient(transport=settings.transport()) as client:
|
||||||
try:
|
for retry_cnt in range(settings.get("get_data_retries", 1)):
|
||||||
if post:
|
try:
|
||||||
response = await client.post(
|
if post:
|
||||||
f"http://{self.ip}:{self.port}/{command}",
|
response = await client.post(
|
||||||
timeout=5,
|
f"http://{self.ip}:{self.port}/{command}",
|
||||||
json={
|
timeout=5,
|
||||||
**parameters,
|
json={
|
||||||
"password": self.pwd,
|
**parameters,
|
||||||
},
|
"password": self.pwd,
|
||||||
)
|
},
|
||||||
else:
|
|
||||||
response = await client.get(
|
|
||||||
f"http://{self.ip}:{self.port}/{command}",
|
|
||||||
timeout=5,
|
|
||||||
)
|
|
||||||
if not response.status_code == 200:
|
|
||||||
if not ignore_errors:
|
|
||||||
raise APIError(
|
|
||||||
f"Web command {command} failed with status code {response.status_code}"
|
|
||||||
)
|
)
|
||||||
return {}
|
else:
|
||||||
json_data = response.json()
|
response = await client.get(
|
||||||
if json_data:
|
f"http://{self.ip}:{self.port}/{command}",
|
||||||
# The API can return a fail status if the miner cannot return the requested data. Catch this and pass
|
timeout=5,
|
||||||
if not json_data.get("result", True) and not post:
|
)
|
||||||
|
if not response.status_code == 200:
|
||||||
if not ignore_errors:
|
if not ignore_errors:
|
||||||
raise APIError(json_data["error"])
|
raise APIError(
|
||||||
return json_data
|
f"Web command {command} failed with status code {response.status_code}"
|
||||||
return {"success": True}
|
)
|
||||||
except (httpx.HTTPError, json.JSONDecodeError, AttributeError):
|
return {}
|
||||||
pass
|
json_data = response.json()
|
||||||
|
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
|
||||||
|
return {"success": True}
|
||||||
|
except (httpx.HTTPError, json.JSONDecodeError, AttributeError):
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user