Skip to content

Commit 2d569d5

Browse files
authored
Merge pull request #22 from wherobots/max/features
Use new runtime names and implement session reuse
2 parents 3dd7a4c + 3deafcb commit 2d569d5

File tree

7 files changed

+296
-230
lines changed

7 files changed

+296
-230
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ from wherobots.db.runtime import Runtime
3333

3434
with connect(
3535
api_key='...',
36-
runtime=Runtime.SEDONA,
36+
runtime=Runtime.TINY,
3737
region=Region.AWS_US_WEST_2) as conn:
3838
curr = conn.cursor()
3939
curr.execute("SHOW SCHEMAS IN wherobots_open_data")
@@ -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.

poetry.lock

Lines changed: 261 additions & 222 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "wherobots-python-dbapi"
3-
version = "0.7.5"
3+
version = "0.8.0"
44
description = "Python DB-API driver for Wherobots DB"
55
authors = ["Maxime Petazzoni <[email protected]>"]
66
license = "Apache 2.0"

tests/smoke.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@
7171
host=args.api_endpoint,
7272
token=token,
7373
api_key=api_key,
74-
runtime=Runtime.SEDONA,
75-
region=Region.AWS_US_WEST_2,
7674
shutdown_after_inactive_seconds=args.shutdown_after_inactive_seconds,
7775
wait_timeout=900,
7876
)

wherobots/db/constants.py

Lines changed: 4 additions & 1 deletion
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-
DEFAULT_RUNTIME: Runtime = Runtime.SEDONA
10+
11+
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,

wherobots/db/runtime.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22

33

44
class Runtime(Enum):
5+
TINY = "tiny"
6+
SMALL = "small"
7+
MEDIUM = "medium"
8+
LARGE = "large"
9+
X_LARGE = "x-large"
10+
XX_LARGE = "2x-large"
11+
XXXX_LARGE = "4x-large"
12+
13+
# HIMEM
14+
MEDIUM_HIMEM = "medium-himem"
15+
LARGE_HIMEM = "large-himem"
16+
X_LARGE_HIMEM = "x-large-himem"
17+
XX_LARGE_HIMEM = "2x-large-himem"
18+
XXXX_LARGE_HIMEM = "4x-large-himem"
19+
20+
# GPU
21+
TINY_A10_GPU = "tiny-a10-gpu"
22+
SMALL_A10_GPU = "small-a10-gpu"
23+
MEDIUM_A10_GPU = "medium-a10-gpu"
24+
25+
# Deprecated names; will be removed in a later major version.
526
SEDONA = "tiny"
627
SAN_FRANCISCO = "small"
728
NEW_YORK = "medium"

0 commit comments

Comments
 (0)