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():
@ -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
def connect_loop():
while True: while True:
try: try:
print(f"[WebSocket] Connecting to {SERVER_URL}...") print(f"[WebSocket] Connecting to {SERVER_URL}...")
sio.connect(SERVER_URL, transports=["websocket"]()) sio.connect(SERVER_URL, transports=["websocket"], wait=False)
break break
except Exception as e: except Exception:
print(f"[WebSocket] Borealis Server is Not Running - Retrying in {retry_interval} seconds...") print(f"[WebSocket] Borealis Server is Not Running - Retrying in {retry_interval} seconds...")
time.sleep(retry_interval) 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
} }