improve logging and some documentation

This commit is contained in:
UpstreamData
2022-07-18 14:38:54 -06:00
parent 98e2cfae84
commit 43b4992cee
4 changed files with 81 additions and 43 deletions

View File

@@ -54,13 +54,11 @@ class BaseMiner:
)
return conn
except Exception as e:
# logging.warning(f"{self} raised an exception: {e}")
raise e
except OSError as e:
logging.warning(f"Connection refused: {self}")
raise e
except Exception as e:
# logging.warning(f"{self} raised an exception: {e}")
raise e
async def fault_light_on(self) -> bool:

View File

@@ -252,6 +252,7 @@ class MinerFactory(metaclass=Singleton):
# create a list of tasks
scan_tasks = []
# for each miner IP that was passed in, add a task to get its class
logging.debug(f"Getting miners with generator: [{ips}]")
for miner in ips:
scan_tasks.append(loop.create_task(self.get_miner(miner)))
# asynchronously run the tasks and return them as they complete
@@ -273,6 +274,7 @@ class MinerFactory(metaclass=Singleton):
ip = ipaddress.ip_address(ip)
# check if the miner already exists in cache
if ip in self.miners:
logging.debug(f"Miner exists in cache: {self.miners[ip]}")
return self.miners[ip]
# if everything fails, the miner is already set to unknown
miner = UnknownMiner(str(ip))
@@ -296,6 +298,9 @@ class MinerFactory(metaclass=Singleton):
ver = new_ver
# if we find the API and model, don't need to loop anymore
if api and model:
logging.debug(
f"Miner api and model found: API - {api}, Model - {model}"
)
break
except asyncio.TimeoutError:
logging.warning(f"{ip}: Get Miner Timed Out")
@@ -339,11 +344,13 @@ class MinerFactory(metaclass=Singleton):
self.miners[ip] = miner
# return the miner
logging.debug(f"Found miner: {miner}")
return miner
def clear_cached_miners(self) -> None:
"""Clear the miner factory cache."""
# empty out self.miners
logging.debug("Clearing MinerFactory cache.")
self.miners = {}
async def _get_miner_type(
@@ -369,12 +376,16 @@ class MinerFactory(metaclass=Singleton):
version = data["version"][0]
except APIError:
logging.debug(f"API Error when getting miner type: {str(ip)}")
try:
# try devdetails and version separately (X19s mainly require this)
# get devdetails and validate
devdetails = await self._send_api_command(str(ip), "devdetails")
validation = await self._validate_command(devdetails)
if not validation[0]:
logging.debug(
f"Splitting commands failed when getting miner type: {str(ip)}"
)
# if devdetails fails try version instead
devdetails = None
@@ -388,12 +399,15 @@ class MinerFactory(metaclass=Singleton):
# if this fails we raise an error to be caught below
if not validation[0]:
logging.debug(
f"get_version failed when getting miner type: {str(ip)}"
)
raise APIError(validation[1])
except APIError as e:
# catch APIError and let the factory know we cant get data
logging.warning(f"{ip}: API Command Error: {e}")
logging.warning(f"{ip}: API Command Error: {e.__name__} - {e}")
return None, None, None
except OSError as e:
except OSError:
# miner refused connection on API port, we wont be able to get data this way
# try ssh
try: