vantiqservicesdk 0.2.0__tar.gz → 0.2.1__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
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: vantiqservicesdk
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: SDK for building Vantiq service connectors in Python
5
5
  Author-email: Vantiq <sfitts@vantiq.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "vantiqservicesdk"
7
- version = "0.2.0"
7
+ version = "0.2.1"
8
8
  description = "SDK for building Vantiq service connectors in Python"
9
9
  authors = [
10
10
  { name = "Vantiq", email = "sfitts@vantiq.com" },
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: vantiqservicesdk
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: SDK for building Vantiq service connectors in Python
5
5
  Author-email: Vantiq <sfitts@vantiq.com>
6
6
  License: MIT
@@ -158,11 +158,11 @@ class BaseVantiqServiceConnector:
158
158
  # noinspection PyBroadException
159
159
  try:
160
160
  await websocket.send({"type": "websocket.send",
161
- "bytes": self._handle_exception(e, response)})
161
+ "bytes": self._handle_exception(e, {}, response)})
162
162
  except Exception:
163
163
  self._logger.error("Caught error sending error response", exc_info=True)
164
164
  continue
165
-
165
+
166
166
  options = request.pop('options', {})
167
167
 
168
168
  # Spawn a task to process the request and possibly send the response
@@ -187,33 +187,32 @@ class BaseVantiqServiceConnector:
187
187
  task.cancel()
188
188
 
189
189
  async def __process_message(self, request: dict) -> Any:
190
+ # Get the procedure name and parameters
190
191
  self._logger.debug('Request was: %s', request)
191
- procedure_name: str = 'unknown'
192
- try:
193
- # Get the procedure name and parameters
194
- procedure_name = request.get("procName")
195
- params = request.get("params")
196
-
197
- # In the future, it should be set by an explicit value isSystemRequest. For compatibility reasons, we
198
- # must accept appending "__system" to the requestId as equivalent
199
- is_system_request = request.get("isSystemRequest", False) or request.get("requestId").endswith("__system")
200
-
201
- # Invoke the procedure and store the result
202
- request_timer = self.__get_resource_metric(self._resources_executions, procedure_name)
203
- with request_timer.time():
204
- result = await self.__invoke(procedure_name, params, is_system_request)
205
- return result
206
- except Exception as e:
207
- # Log and record error
208
- self._logger.debug(f"Error invoking procedure {procedure_name}", exc_info=e)
209
- self.__get_resource_metric(self._failed_requests, procedure_name).inc()
210
- raise e
211
-
192
+ procedure_name: str = request.get("procName", "unknown")
193
+ params = request.get("params")
194
+
195
+ # In the future, it should be set by an explicit value isSystemRequest. For compatibility reasons, we
196
+ # must accept appending "__system" to the requestId as equivalent
197
+ is_system_request = request.get("isSystemRequest", False) or request.get("requestId").endswith("__system")
198
+
199
+ # Invoke the procedure and store the result
200
+ request_timer = self.__get_resource_metric(self._resources_executions, procedure_name)
201
+ with request_timer.time():
202
+ result = await self.__invoke(procedure_name, params, is_system_request)
203
+ return result
204
+
212
205
  async def __fire_forget(self, websocket: WebSocket, request: dict) -> None:
206
+ # Send a response to indicate that the request was received
213
207
  response = self.encode_response({"requestId": request.get("requestId"), "isEOF": True})
214
208
  await websocket.send({"type": "websocket.send", "bytes": response})
215
- await self.__process_message(request)
216
-
209
+
210
+ # Process the message and ignore any exceptions
211
+ try:
212
+ await self.__process_message(request)
213
+ except Exception as e:
214
+ self._handle_exception(e, request, None)
215
+
217
216
  async def __request_response(self, websocket: WebSocket, request: dict) -> None:
218
217
  # Set up default response and invoke the procedure
219
218
  response = {"requestId": request.get("requestId"), "isEOF": True}
@@ -239,13 +238,19 @@ class BaseVantiqServiceConnector:
239
238
  self._check_message_size(encoded_response)
240
239
 
241
240
  except Exception as e:
242
- encoded_response = self._handle_exception(e, response)
241
+ encoded_response = self._handle_exception(e, request, response)
243
242
 
244
243
  # Send the response
245
244
  await websocket.send({"type": "websocket.send", "bytes": encoded_response})
246
245
 
247
- @staticmethod
248
- def _handle_exception(e: Exception, response: dict) -> bytes:
246
+ def _handle_exception(self, e: Exception, request: dict, response: dict) -> bytes:
247
+ # Log and record error
248
+ procedure_name = request.get("procName", "unknown")
249
+ self._logger.debug(f"Error invoking procedure {procedure_name}", exc_info=e)
250
+ self.__get_resource_metric(self._failed_requests, procedure_name).inc()
251
+ if response is None:
252
+ return b''
253
+
249
254
  # Remove the result (if any) and add the error message
250
255
  error_str = str(e)
251
256
  response.pop("result", None)
@@ -255,7 +260,7 @@ class BaseVantiqServiceConnector:
255
260
 
256
261
  # Serialize to JSON and encode (duplicated here to record JSON serialization errors)
257
262
  return json.dumps(response, separators=(",", ":"), ensure_ascii=False).encode("utf-8")
258
-
263
+
259
264
  def _check_message_size(self, encoded_message: bytes) -> None:
260
265
  config = self._client_config or {}
261
266
  max_size = config.get("maxMessageSize", -1)