bug: fix timeout references in MinerFactory and fix MinerNetwork instantiation.
This commit is contained in:
@@ -45,9 +45,7 @@ from pyasic.miners.innosilicon import *
|
||||
from pyasic.miners.unknown import UnknownMiner
|
||||
from pyasic.miners.whatsminer import *
|
||||
|
||||
TIMEOUT = 20
|
||||
RETRIES = 3
|
||||
|
||||
from pyasic import settings
|
||||
|
||||
class MinerTypes(enum.Enum):
|
||||
ANTMINER = 0
|
||||
@@ -419,10 +417,10 @@ class MinerFactory:
|
||||
|
||||
miner_type = None
|
||||
|
||||
for _ in range(RETRIES):
|
||||
for _ in range(settings.get("factory_get_retries", 1)):
|
||||
task = asyncio.create_task(self._get_miner_type(ip))
|
||||
try:
|
||||
miner_type = await asyncio.wait_for(task, timeout=TIMEOUT)
|
||||
miner_type = await asyncio.wait_for(task, timeout=settings.get("factory_get_timeout", 3))
|
||||
except asyncio.TimeoutError:
|
||||
task.cancel()
|
||||
else:
|
||||
@@ -447,7 +445,7 @@ class MinerFactory:
|
||||
if fn is not None:
|
||||
task = asyncio.create_task(fn(ip))
|
||||
try:
|
||||
miner_model = await asyncio.wait_for(task, timeout=TIMEOUT)
|
||||
miner_model = await asyncio.wait_for(task, timeout=settings.get("factory_get_timeout", 3))
|
||||
except asyncio.TimeoutError:
|
||||
task.cancel()
|
||||
|
||||
@@ -538,7 +536,7 @@ class MinerFactory:
|
||||
data = b""
|
||||
try:
|
||||
reader, writer = await asyncio.wait_for(
|
||||
asyncio.open_connection(str(ip), 4028), timeout=30
|
||||
asyncio.open_connection(str(ip), 4028), timeout=settings.get("factory_get_timeout", 3)
|
||||
)
|
||||
except (ConnectionError, OSError, asyncio.TimeoutError):
|
||||
return
|
||||
@@ -609,7 +607,7 @@ class MinerFactory:
|
||||
data = await session.get(
|
||||
f"http://{str(ip)}{location}",
|
||||
auth=auth,
|
||||
timeout=30,
|
||||
timeout=settings.get("factory_get_timeout", 3),
|
||||
)
|
||||
except (httpx.HTTPError, asyncio.TimeoutError):
|
||||
logger.info(f"{ip}: Web command timeout.")
|
||||
|
||||
@@ -37,7 +37,7 @@ class MinerNetwork:
|
||||
return len(self.hosts)
|
||||
|
||||
@classmethod
|
||||
def from_list(cls, addresses: list):
|
||||
def from_list(cls, addresses: list) -> "MinerNetwork":
|
||||
"""Parse a list of address constructors into a MinerNetwork.
|
||||
|
||||
Parameters:
|
||||
@@ -46,10 +46,10 @@ class MinerNetwork:
|
||||
hosts = []
|
||||
for address in addresses:
|
||||
hosts = [*hosts, *cls.from_address(address)]
|
||||
return sorted(list(set(hosts)))
|
||||
return cls(sorted(list(set(hosts))))
|
||||
|
||||
@classmethod
|
||||
def from_address(cls, address: str):
|
||||
def from_address(cls, address: str) -> "MinerNetwork":
|
||||
"""Parse an address constructor into a MinerNetwork.
|
||||
|
||||
Parameters:
|
||||
@@ -63,7 +63,7 @@ class MinerNetwork:
|
||||
return cls.from_octets(*octets)
|
||||
|
||||
@classmethod
|
||||
def from_octets(cls, oct_1: str, oct_2: str, oct_3: str, oct_4: str):
|
||||
def from_octets(cls, oct_1: str, oct_2: str, oct_3: str, oct_4: str) -> "MinerNetwork":
|
||||
"""Parse 4 octet constructors into a MinerNetwork.
|
||||
|
||||
Parameters:
|
||||
@@ -96,16 +96,16 @@ class MinerNetwork:
|
||||
".".join([oct_1_val, oct_2_val, oct_3_val, oct_4_val])
|
||||
)
|
||||
)
|
||||
return sorted(hosts)
|
||||
return cls(sorted(hosts))
|
||||
|
||||
@classmethod
|
||||
def from_subnet(cls, subnet: str):
|
||||
def from_subnet(cls, subnet: str) -> "MinerNetwork":
|
||||
"""Parse a subnet into a MinerNetwork.
|
||||
|
||||
Parameters:
|
||||
subnet: A subnet string, such as `"10.0.0.1/24"`.
|
||||
"""
|
||||
return list(ipaddress.ip_network(subnet, strict=False).hosts())
|
||||
return cls(list(ipaddress.ip_network(subnet, strict=False).hosts()))
|
||||
|
||||
async def scan_network_for_miners(self) -> List[AnyMiner]:
|
||||
"""Scan the network for miners, and return found miners as a list.
|
||||
|
||||
@@ -21,6 +21,7 @@ _settings = { # defaults
|
||||
"network_ping_timeout": 3,
|
||||
"network_scan_threads": 300,
|
||||
"factory_get_retries": 1,
|
||||
"factory_get_timeout": 3,
|
||||
"get_data_retries": 1,
|
||||
"default_whatsminer_password": "admin",
|
||||
"default_innosilicon_password": "admin",
|
||||
|
||||
Reference in New Issue
Block a user