wherobots-python-dbapi 0.6.2__tar.gz → 0.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wherobots-python-dbapi
3
- Version: 0.6.2
3
+ Version: 0.7.0
4
4
  Summary: Python DB-API driver for Wherobots DB
5
5
  License: Apache 2.0
6
6
  Author: Maxime Petazzoni
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "wherobots-python-dbapi"
3
- version = "0.6.2"
3
+ version = "0.7.0"
4
4
  description = "Python DB-API driver for Wherobots DB"
5
5
  authors = ["Maxime Petazzoni <max@wherobots.com>"]
6
6
  license = "Apache 2.0"
@@ -1,5 +1,5 @@
1
1
  from enum import auto
2
- from strenum import LowercaseStrEnum
2
+ from strenum import LowercaseStrEnum, StrEnum
3
3
 
4
4
  from .region import Region
5
5
  from .runtime import Runtime
@@ -67,3 +67,39 @@ class GeometryRepresentation(LowercaseStrEnum):
67
67
  EWKT = auto()
68
68
  EWKB = auto()
69
69
  GEOJSON = auto()
70
+
71
+
72
+ class AppStatus(StrEnum):
73
+ PENDING = auto()
74
+ PREPARING = auto()
75
+ PREPARE_FAILED = auto()
76
+ REQUESTED = auto()
77
+ DEPLOYING = auto()
78
+ DEPLOY_FAILED = auto()
79
+ DEPLOYED = auto()
80
+ INITIALIZING = auto()
81
+ INIT_FAILED = auto()
82
+ READY = auto()
83
+ DESTROY_REQUESTED = auto()
84
+ DESTROYING = auto()
85
+ DESTROY_FAILED = auto()
86
+ DESTROYED = auto()
87
+
88
+ def is_starting(self):
89
+ return self in (
90
+ AppStatus.PENDING,
91
+ AppStatus.PREPARING,
92
+ AppStatus.REQUESTED,
93
+ AppStatus.DEPLOYING,
94
+ AppStatus.DEPLOYED,
95
+ AppStatus.INITIALIZING,
96
+ )
97
+
98
+ def is_terminal_state(self):
99
+ return self in (
100
+ AppStatus.PREPARE_FAILED,
101
+ AppStatus.DEPLOY_FAILED,
102
+ AppStatus.INIT_FAILED,
103
+ AppStatus.DESTROY_FAILED,
104
+ AppStatus.DESTROYED,
105
+ )
@@ -21,9 +21,10 @@ from .constants import (
21
21
  DEFAULT_SESSION_WAIT_TIMEOUT_SECONDS,
22
22
  MAX_MESSAGE_SIZE,
23
23
  PROTOCOL_VERSION,
24
- ResultsFormat,
24
+ AppStatus,
25
25
  DataCompression,
26
26
  GeometryRepresentation,
27
+ ResultsFormat,
27
28
  )
28
29
  from .errors import (
29
30
  InterfaceError,
@@ -107,11 +108,11 @@ def connect(
107
108
  r = requests.get(session_id_url, headers=headers)
108
109
  r.raise_for_status()
109
110
  payload = r.json()
110
- status = payload.get("status")
111
+ status = AppStatus(payload.get("status"))
111
112
  logging.info(" ... %s", status)
112
- if status in ("REQUESTED", "DEPLOYING", "DEPLOYED", "INITIALIZING"):
113
+ if status.is_starting():
113
114
  raise tenacity.TryAgain("SQL Session is not ready yet")
114
- elif status == "READY":
115
+ elif status == AppStatus.READY:
115
116
  return payload["appMeta"]["url"]
116
117
  else:
117
118
  logging.error("SQL session creation failed: %s; should not retry.", status)
@@ -120,6 +121,7 @@ def connect(
120
121
  try:
121
122
  logging.info("Getting SQL session status from %s ...", session_id_url)
122
123
  session_uri = get_session_uri()
124
+ logging.debug("SQL session URI from app status: %s", session_uri)
123
125
  except Exception as e:
124
126
  raise InterfaceError("Could not acquire SQL session!", e)
125
127