improved send command functionality with a generator and added progress to it
This commit is contained in:
@@ -13,6 +13,7 @@ class BaseMiner:
|
|||||||
self.light = None
|
self.light = None
|
||||||
self.hostname = None
|
self.hostname = None
|
||||||
self.nominal_chips = 1
|
self.nominal_chips = 1
|
||||||
|
self.version = None
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"{'' if not self.api_type else self.api_type} {'' if not self.model else self.model}: {str(self.ip)}"
|
return f"{'' if not self.api_type else self.api_type} {'' if not self.model else self.model}: {str(self.ip)}"
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
from miners.miner_factory import MinerFactory
|
from miners.miner_factory import MinerFactory
|
||||||
from tools.cfg_util.layout import window
|
from tools.cfg_util.layout import window, update_prog_bar
|
||||||
from tools.cfg_util.tables import TableManager
|
from tools.cfg_util.tables import TableManager
|
||||||
from tools.cfg_util.decorators import disable_buttons
|
from tools.cfg_util.decorators import disable_buttons
|
||||||
|
from settings import CFG_UTIL_CONFIG_THREADS as COMMAND_THREADS
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
@disable_buttons("Flashing Lights")
|
@disable_buttons("Flashing Lights")
|
||||||
@@ -62,15 +65,44 @@ async def btn_backend(ip_idxs: list):
|
|||||||
|
|
||||||
@disable_buttons("Sending Command")
|
@disable_buttons("Sending Command")
|
||||||
async def btn_command(ip_idxs: list, command: str):
|
async def btn_command(ip_idxs: list, command: str):
|
||||||
|
prog_bar_len = 0
|
||||||
|
await update_prog_bar(prog_bar_len, len(ip_idxs))
|
||||||
table_manager = TableManager()
|
table_manager = TableManager()
|
||||||
_table = window["cmd_table"].Widget
|
_table = window["cmd_table"].Widget
|
||||||
|
miners = []
|
||||||
iids = _table.get_children()
|
iids = _table.get_children()
|
||||||
for idx in ip_idxs:
|
for idx in ip_idxs:
|
||||||
item = _table.item(iids[idx])
|
item = _table.item(iids[idx])
|
||||||
ip = item["values"][0]
|
ip = item["values"][0]
|
||||||
miner = await MinerFactory().get_miner(ip)
|
miner = await MinerFactory().get_miner(ip)
|
||||||
success = await miner.send_ssh_command(command)
|
miners.append(miner)
|
||||||
if not isinstance(success, str):
|
|
||||||
|
sent = send_command_generator(miners, command)
|
||||||
|
async for done in sent:
|
||||||
|
success = done["Status"]
|
||||||
|
if not isinstance(done["Status"], str):
|
||||||
success = f"Command {command} failed."
|
success = f"Command {command} failed."
|
||||||
table_manager.data[ip]["Output"] = success
|
table_manager.data[done["IP"]]["Output"] = success
|
||||||
table_manager.update_tables()
|
prog_bar_len += 1
|
||||||
|
table_manager.update_tables()
|
||||||
|
await update_prog_bar(prog_bar_len, len(ip_idxs))
|
||||||
|
|
||||||
|
|
||||||
|
async def send_command_generator(miners: list, command: str):
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
command_tasks = []
|
||||||
|
for miner in miners:
|
||||||
|
if len(command_tasks) >= COMMAND_THREADS:
|
||||||
|
cmd_sent = asyncio.as_completed(command_tasks)
|
||||||
|
command_tasks = []
|
||||||
|
for done in cmd_sent:
|
||||||
|
yield await done
|
||||||
|
command_tasks.append(loop.create_task(_send_ssh_command(miner, command)))
|
||||||
|
cmd_sent = asyncio.as_completed(command_tasks)
|
||||||
|
for done in cmd_sent:
|
||||||
|
yield await done
|
||||||
|
|
||||||
|
|
||||||
|
async def _send_ssh_command(miner, command: str):
|
||||||
|
proc = await miner.send_ssh_command(command)
|
||||||
|
return {"IP": miner.ip, "Status": proc}
|
||||||
|
|||||||
Reference in New Issue
Block a user