Added Automatic Agent Reconnection Logic

This commit is contained in:
Nicole Rappe 2025-04-30 02:54:16 -06:00
parent c4ce9a6bd1
commit bf4185643e
2 changed files with 17 additions and 12 deletions

View File

@ -28,7 +28,8 @@ running_roles = {}
running_threads = {} running_threads = {}
# ---------------- Socket Setup ---------------- # ---------------- Socket Setup ----------------
sio = socketio.Client() # Enable automatic reconnection with retries in background
sio = socketio.Client(reconnection=True, reconnection_attempts=0, reconnection_delay=5)
@sio.event @sio.event
def connect(): def connect():
@ -157,7 +158,7 @@ def run_screenshot_loop(node_id, cfg):
interval = cfg.get("interval", 1000) interval = cfg.get("interval", 1000)
visible = cfg.get("visible", True) visible = cfg.get("visible", True)
x = cfg.get("x", 100) x = cfg.get("x", 100)
y = cfg.get("y", 100) y = cfg.get("y", 100)
w = cfg.get("w", 300) w = cfg.get("w", 300)
h = cfg.get("h", 200) h = cfg.get("h", 200)
@ -196,12 +197,16 @@ def run_screenshot_loop(node_id, cfg):
if __name__ == "__main__": if __name__ == "__main__":
app_instance = QtWidgets.QApplication(sys.argv) app_instance = QtWidgets.QApplication(sys.argv)
retry_interval = 5 # seconds between connection attempts retry_interval = 5 # seconds between connection attempts
while True:
try: def connect_loop():
print(f"[WebSocket] Connecting to {SERVER_URL}...") while True:
sio.connect(SERVER_URL, transports=["websocket"]()) try:
break print(f"[WebSocket] Connecting to {SERVER_URL}...")
except Exception as e: sio.connect(SERVER_URL, transports=["websocket"], wait=False)
print(f"[WebSocket] Borealis Server is Not Running - Retrying in {retry_interval} seconds...") break
time.sleep(retry_interval) except Exception:
print(f"[WebSocket] Borealis Server is Not Running - Retrying in {retry_interval} seconds...")
time.sleep(retry_interval)
threading.Thread(target=connect_loop, daemon=True).start()
sys.exit(app_instance.exec_()) sys.exit(app_instance.exec_())

View File

@ -200,7 +200,7 @@ switch ($choice) {
<# <#
Step: Create Virtual Environment & Copy Agent Script Step: Create Virtual Environment & Copy Agent Script
#> #>
Run-Step "Create Virtual Python Environment for Agent" { Run-Step "Create Virtual Python Environment" {
if (-not (Test-Path "$venvFolder\Scripts\Activate")) { if (-not (Test-Path "$venvFolder\Scripts\Activate")) {
& $pythonExe -m venv $venvFolder & $pythonExe -m venv $venvFolder
} }
@ -215,7 +215,7 @@ switch ($choice) {
<# <#
Step: Install Agent Dependencies Step: Install Agent Dependencies
#> #>
Run-Step "Install Python Dependencies for Agent" { Run-Step "Install Python Dependencies" {
if (Test-Path $agentRequirements) { if (Test-Path $agentRequirements) {
& $venvPython -m pip install --disable-pip-version-check -q -r $agentRequirements | Out-Null & $venvPython -m pip install --disable-pip-version-check -q -r $agentRequirements | Out-Null
} }