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