Skip to content

Commit 0b1b413

Browse files
authored
Merge pull request #30 from wherobots/simon/session-type-support
feat(EWT-2214): adds session type support
2 parents 651a5d6 + 8dcd235 commit 0b1b413

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

README.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ 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 reused for this
86-
connection. This is the default behavior.
84+
* `session_type`: `"single"` or `"multi"`; if set to `"single"`, then each call
85+
to `Connection.connect()` establishes an exclusive connection to a
86+
Wherobots runtime; if set to "multi", then multiple `Connection.connect()`
87+
calls with the same arguments and credentials will connect to the same
88+
shared Wherobots runtime; `"single"` is the default.
89+
90+
Consider multi-session for potential cost savings, but be mindful of
91+
performance impacts from shared resources. You might need to adjust
92+
cluster size if slowdowns occur, which could affect overall cost.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "wherobots-python-dbapi"
33

44
[tool.poetry]
55
name = "wherobots-python-dbapi"
6-
version = "0.11.1"
6+
version = "0.12.0"
77
description = "Python DB-API driver for Wherobots DB"
88
authors = ["Maxime Petazzoni <[email protected]>"]
99
license = "Apache 2.0"

wherobots/db/constants.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44

55
from .region import Region
66
from .runtime import Runtime
7+
from .session_type import SessionType
78

89

910
DEFAULT_ENDPOINT: str = "api.cloud.wherobots.com" # "api.cloud.wherobots.com"
1011
STAGING_ENDPOINT: str = "api.staging.wherobots.com" # "api.staging.wherobots.com"
1112

1213
DEFAULT_RUNTIME: Runtime = Runtime.TINY
1314
DEFAULT_REGION: Region = Region.AWS_US_WEST_2
15+
DEFAULT_SESSION_TYPE: SessionType = SessionType.SINGLE
1416
DEFAULT_READ_TIMEOUT_SECONDS: float = 0.25
1517
DEFAULT_SESSION_WAIT_TIMEOUT_SECONDS: float = 900
16-
DEFAULT_REUSE_SESSION: bool = True
1718

1819
MAX_MESSAGE_SIZE: int = 100 * 2**20 # 100MiB
1920
PROTOCOL_VERSION: Version = Version("1.0.0")

wherobots/db/driver.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
A PEP-0249 compatible driver for interfacing with Wherobots DB.
44
"""
5+
56
import ssl
67
from importlib import metadata
78
from importlib.metadata import PackageNotFoundError
@@ -19,16 +20,17 @@
1920
from .constants import (
2021
DEFAULT_ENDPOINT,
2122
DEFAULT_REGION,
22-
DEFAULT_REUSE_SESSION,
2323
DEFAULT_RUNTIME,
2424
DEFAULT_READ_TIMEOUT_SECONDS,
25+
DEFAULT_SESSION_TYPE,
2526
DEFAULT_SESSION_WAIT_TIMEOUT_SECONDS,
2627
MAX_MESSAGE_SIZE,
2728
PROTOCOL_VERSION,
2829
AppStatus,
2930
DataCompression,
3031
GeometryRepresentation,
3132
ResultsFormat,
33+
SessionType,
3234
)
3335
from .errors import (
3436
InterfaceError,
@@ -62,7 +64,7 @@ def connect(
6264
region: Union[Region, None] = None,
6365
wait_timeout: float = DEFAULT_SESSION_WAIT_TIMEOUT_SECONDS,
6466
read_timeout: float = DEFAULT_READ_TIMEOUT_SECONDS,
65-
reuse_session: bool = DEFAULT_REUSE_SESSION,
67+
session_type: Union[SessionType, None] = None,
6668
shutdown_after_inactive_seconds: Union[int, None] = None,
6769
results_format: Union[ResultsFormat, None] = None,
6870
data_compression: Union[DataCompression, None] = None,
@@ -82,10 +84,10 @@ def connect(
8284
host = host or DEFAULT_ENDPOINT
8385
runtime = runtime or DEFAULT_RUNTIME
8486
region = region or DEFAULT_REGION
87+
session_type = session_type or DEFAULT_SESSION_TYPE
8588

8689
logging.info(
87-
"%s %s runtime in %s from %s ...",
88-
"Recycling" if reuse_session else "Requesting",
90+
"Requesting %s runtime in %s from %s ...",
8991
runtime.value,
9092
region.value,
9193
host,
@@ -98,7 +100,7 @@ def connect(
98100
try:
99101
resp = requests.post(
100102
url=f"{host}/sql/session",
101-
params={"region": region.value, "reuse_session": reuse_session},
103+
params={"region": region.value, "sessionType": session_type.value},
102104
json={
103105
"runtimeId": runtime.value,
104106
"shutdownAfterInactiveSeconds": shutdown_after_inactive_seconds,

wherobots/db/session_type.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from enum import auto
2+
from strenum import LowercaseStrEnum
3+
4+
5+
class SessionType(LowercaseStrEnum):
6+
SINGLE = auto()
7+
MULTI = auto()

0 commit comments

Comments
 (0)