Skip to content

Commit 5d4fe50

Browse files
committed
feat: make read timeout configurable
1 parent 360f19d commit 5d4fe50

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

wherobots/db/connection.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,13 @@ class Connection:
4949
corresponding query state. Queries are tracked by their unique execution ID.
5050
"""
5151

52-
def __init__(self, ws: websockets.sync.client.ClientConnection):
52+
def __init__(
53+
self,
54+
ws: websockets.sync.client.ClientConnection,
55+
read_timeout: float = DEFAULT_READ_TIMEOUT_SECONDS,
56+
):
5357
self.__ws = ws
58+
self.__read_timeout = read_timeout
5459
self.__queries: dict[str, Query] = {}
5560
self.__thread = threading.Thread(
5661
target=self.__main_loop, daemon=True, name="wherobots-connection"
@@ -168,7 +173,7 @@ def __send(self, message: dict[str, Any]) -> None:
168173
self.__ws.send(json.dumps(message))
169174

170175
def __recv(self) -> dict[str, Any]:
171-
frame = self.__ws.recv(timeout=DEFAULT_READ_TIMEOUT_SECONDS)
176+
frame = self.__ws.recv(timeout=self.__read_timeout)
172177
if isinstance(frame, str):
173178
message = json.loads(frame)
174179
elif isinstance(frame, bytes):

wherobots/db/constants.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
from .runtime import Runtime
55

66

7-
DEFAULT_ENDPOINT = "api.wherobots.services" # "api.cloud.wherobots.com"
8-
STAGING_ENDPOINT = "api.staging.wherobots.services" # "api.staging.wherobots.com"
9-
DEFAULT_RUNTIME = Runtime.SEDONA
10-
DEFAULT_REGION = Region.AWS_US_WEST_2
11-
DEFAULT_READ_TIMEOUT_SECONDS = 0.5
12-
DEFAULT_SESSION_WAIT_TIMEOUT_SECONDS = 300
13-
MAX_MESSAGE_SIZE = 100 * 2**20 # 100MiB
7+
DEFAULT_ENDPOINT: str = "api.wherobots.services" # "api.cloud.wherobots.com"
8+
STAGING_ENDPOINT: str = "api.staging.wherobots.services" # "api.staging.wherobots.com"
9+
DEFAULT_RUNTIME: Runtime = Runtime.SEDONA
10+
DEFAULT_REGION: Region = Region.AWS_US_WEST_2
11+
DEFAULT_READ_TIMEOUT_SECONDS: float = 0.25
12+
DEFAULT_SESSION_WAIT_TIMEOUT_SECONDS: float = 300
13+
MAX_MESSAGE_SIZE: int = 100 * 2**20 # 100MiB
1414

1515

1616
class ExecutionState(StrEnum):

0 commit comments

Comments
 (0)