feat(backend_server.py): add ACK_TIMEOUT constant

This commit is contained in:
2026-03-03 20:41:58 +01:00
parent c88e39c735
commit a9bace8aca

View File

@@ -6,7 +6,7 @@ import selectors
import socket import socket
import threading import threading
import time import time
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING, Any, Final
import yaml import yaml
from judas_protocol import Category, ControlAction, Message from judas_protocol import Category, ControlAction, Message
@@ -21,6 +21,8 @@ if TYPE_CHECKING:
class BackendServer: class BackendServer:
ACK_TIMEOUT: Final[float] = 5.0 # seconds
def __init__(self, host: str = "0.0.0.0", port: int = 3692) -> None: def __init__(self, host: str = "0.0.0.0", port: int = 3692) -> None:
"""Initialize the backend server. """Initialize the backend server.
@@ -356,12 +358,13 @@ class BackendServer:
# check pending ACKs # check pending ACKs
for client, msg, timestamp in self.pending_acks[:]: for client, msg, timestamp in self.pending_acks[:]:
if time.time() - timestamp > 5: # 5 second timeout if time.time() - timestamp > self.ACK_TIMEOUT:
self.logger.warning( self.logger.warning(
f"ACK timeout for message {msg.id} to {client}, resending..." f"ACK timeout for message {msg.id} to {client}, resending..."
) )
self.send(client, msg) self.send(client, msg)
self.pending_acks.remove((client, msg, timestamp)) self.pending_acks.remove((client, msg, timestamp))
time.sleep(0.001) # prevent 100% CPU usage time.sleep(0.001) # prevent 100% CPU usage
except Exception as e: except Exception as e: