Skip to content

Commit

Permalink
Merge pull request #30 from wherobots/simon/session-type-support
Browse files Browse the repository at this point in the history
feat(EWT-2214): adds session type support
  • Loading branch information
sfishel18 authored Mar 4, 2025
2 parents 651a5d6 + 8dcd235 commit 0b1b413
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ users may find useful:
client application. The default is EWKT (string) and the most
convenient for human inspection while still being usable by
libraries like Shapely.
* `reuse_session`: controls whether an existing runtime of the same type
and in the same region that is available should be reused for this
connection. This is the default behavior.
* `session_type`: `"single"` or `"multi"`; if set to `"single"`, then each call
to `Connection.connect()` establishes an exclusive connection to a
Wherobots runtime; if set to "multi", then multiple `Connection.connect()`
calls with the same arguments and credentials will connect to the same
shared Wherobots runtime; `"single"` is the default.

Consider multi-session for potential cost savings, but be mindful of
performance impacts from shared resources. You might need to adjust
cluster size if slowdowns occur, which could affect overall cost.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "wherobots-python-dbapi"

[tool.poetry]
name = "wherobots-python-dbapi"
version = "0.11.1"
version = "0.12.0"
description = "Python DB-API driver for Wherobots DB"
authors = ["Maxime Petazzoni <[email protected]>"]
license = "Apache 2.0"
Expand Down
3 changes: 2 additions & 1 deletion wherobots/db/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

from .region import Region
from .runtime import Runtime
from .session_type import SessionType


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

DEFAULT_RUNTIME: Runtime = Runtime.TINY
DEFAULT_REGION: Region = Region.AWS_US_WEST_2
DEFAULT_SESSION_TYPE: SessionType = SessionType.SINGLE
DEFAULT_READ_TIMEOUT_SECONDS: float = 0.25
DEFAULT_SESSION_WAIT_TIMEOUT_SECONDS: float = 900
DEFAULT_REUSE_SESSION: bool = True

MAX_MESSAGE_SIZE: int = 100 * 2**20 # 100MiB
PROTOCOL_VERSION: Version = Version("1.0.0")
Expand Down
12 changes: 7 additions & 5 deletions wherobots/db/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
A PEP-0249 compatible driver for interfacing with Wherobots DB.
"""

import ssl
from importlib import metadata
from importlib.metadata import PackageNotFoundError
Expand All @@ -19,16 +20,17 @@
from .constants import (
DEFAULT_ENDPOINT,
DEFAULT_REGION,
DEFAULT_REUSE_SESSION,
DEFAULT_RUNTIME,
DEFAULT_READ_TIMEOUT_SECONDS,
DEFAULT_SESSION_TYPE,
DEFAULT_SESSION_WAIT_TIMEOUT_SECONDS,
MAX_MESSAGE_SIZE,
PROTOCOL_VERSION,
AppStatus,
DataCompression,
GeometryRepresentation,
ResultsFormat,
SessionType,
)
from .errors import (
InterfaceError,
Expand Down Expand Up @@ -62,7 +64,7 @@ def connect(
region: Union[Region, None] = None,
wait_timeout: float = DEFAULT_SESSION_WAIT_TIMEOUT_SECONDS,
read_timeout: float = DEFAULT_READ_TIMEOUT_SECONDS,
reuse_session: bool = DEFAULT_REUSE_SESSION,
session_type: Union[SessionType, None] = None,
shutdown_after_inactive_seconds: Union[int, None] = None,
results_format: Union[ResultsFormat, None] = None,
data_compression: Union[DataCompression, None] = None,
Expand All @@ -82,10 +84,10 @@ def connect(
host = host or DEFAULT_ENDPOINT
runtime = runtime or DEFAULT_RUNTIME
region = region or DEFAULT_REGION
session_type = session_type or DEFAULT_SESSION_TYPE

logging.info(
"%s %s runtime in %s from %s ...",
"Recycling" if reuse_session else "Requesting",
"Requesting %s runtime in %s from %s ...",
runtime.value,
region.value,
host,
Expand All @@ -98,7 +100,7 @@ def connect(
try:
resp = requests.post(
url=f"{host}/sql/session",
params={"region": region.value, "reuse_session": reuse_session},
params={"region": region.value, "sessionType": session_type.value},
json={
"runtimeId": runtime.value,
"shutdownAfterInactiveSeconds": shutdown_after_inactive_seconds,
Expand Down
7 changes: 7 additions & 0 deletions wherobots/db/session_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from enum import auto
from strenum import LowercaseStrEnum


class SessionType(LowercaseStrEnum):
SINGLE = auto()
MULTI = auto()

0 comments on commit 0b1b413

Please sign in to comment.