Skip to content

Commit 86749a8

Browse files
committed
feat: reuse available session by default
1 parent 6914d38 commit 86749a8

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,6 @@ users may find useful:
8181
client application. The default is EWKT (string) and the most
8282
convenient for human inspection while still being usable by
8383
libraries like Shapely.
84+
* `reuse_session`: controls whether an existing runtime of the same type
85+
and in the same region that is available should be re-used for this
86+
connection. This is the default behavior.

wherobots/db/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77

88
DEFAULT_ENDPOINT: str = "api.cloud.wherobots.com" # "api.cloud.wherobots.com"
99
STAGING_ENDPOINT: str = "api.staging.wherobots.com" # "api.staging.wherobots.com"
10+
1011
DEFAULT_RUNTIME: Runtime = Runtime.TINY
1112
DEFAULT_REGION: Region = Region.AWS_US_WEST_2
1213
DEFAULT_READ_TIMEOUT_SECONDS: float = 0.25
1314
DEFAULT_SESSION_WAIT_TIMEOUT_SECONDS: float = 900
15+
DEFAULT_REUSE_SESSION: bool = True
16+
1417
MAX_MESSAGE_SIZE: int = 100 * 2**20 # 100MiB
1518
PROTOCOL_VERSION: str = "1.0.0"
1619

wherobots/db/driver.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from .constants import (
2020
DEFAULT_ENDPOINT,
2121
DEFAULT_REGION,
22+
DEFAULT_REUSE_SESSION,
2223
DEFAULT_RUNTIME,
2324
DEFAULT_READ_TIMEOUT_SECONDS,
2425
DEFAULT_SESSION_WAIT_TIMEOUT_SECONDS,
@@ -62,6 +63,7 @@ def connect(
6263
region: Region = None,
6364
wait_timeout: float = DEFAULT_SESSION_WAIT_TIMEOUT_SECONDS,
6465
read_timeout: float = DEFAULT_READ_TIMEOUT_SECONDS,
66+
reuse_session: bool = DEFAULT_REUSE_SESSION,
6567
shutdown_after_inactive_seconds: Union[int, None] = None,
6668
results_format: Union[ResultsFormat, None] = None,
6769
data_compression: Union[DataCompression, None] = None,
@@ -83,8 +85,8 @@ def connect(
8385
region = region or DEFAULT_REGION
8486

8587
logging.info(
86-
"Requesting %s/%s runtime in %s from %s ...",
87-
runtime.name,
88+
"%s %s runtime in %s from %s ...",
89+
"Recycling" if reuse_session else "Requesting",
8890
runtime.value,
8991
region.value,
9092
host,
@@ -97,7 +99,7 @@ def connect(
9799
try:
98100
resp = requests.post(
99101
url=f"{host}/sql/session",
100-
params={"region": region.value},
102+
params={"region": region.value, "reuse_session": reuse_session},
101103
json={
102104
"runtimeId": runtime.value,
103105
"shutdownAfterInactiveSeconds": shutdown_after_inactive_seconds,

0 commit comments

Comments
 (0)