omnata-plugin-runtime 0.4.0a90__tar.gz → 0.4.1__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omnata-plugin-runtime
3
- Version: 0.4.0a90
3
+ Version: 0.4.1
4
4
  Summary: Classes and common runtime components for building and running Omnata Plugins
5
5
  Author: James Weakley
6
6
  Author-email: james.weakley@omnata.com
@@ -25,6 +25,7 @@ Requires-Dist: pytz (<=2023.3.post1)
25
25
  Requires-Dist: requests (>=2,<=2.31.0)
26
26
  Requires-Dist: setuptools (>=68.2.2)
27
27
  Requires-Dist: snowflake-snowpark-python (>=1,<2)
28
+ Requires-Dist: tenacity (>=8,<=8.2.2)
28
29
  Requires-Dist: tomlkit (>=0.11.1)
29
30
  Requires-Dist: urllib3 (<=2.1.0)
30
31
  Requires-Dist: wheel (<=0.41.2)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "omnata-plugin-runtime"
3
- version = "0.4.0-a90"
3
+ version = "0.4.1"
4
4
  description = "Classes and common runtime components for building and running Omnata Plugins"
5
5
  authors = ["James Weakley <james.weakley@omnata.com>"]
6
6
  readme = "README.md"
@@ -26,6 +26,7 @@ pytz = "<=2023.3.post1" # latest version available on Snowflake Anaconda
26
26
  requests = "^2, <=2.31.0" # latest version available on Snowflake Anaconda
27
27
  setuptools = ">=68.2.2" # 68.2.2 was latest version available on Snowflake Anaconda
28
28
  tomlkit = ">=0.11.1" # 0.11.1 was latest version available on Snowflake Anaconda
29
+ tenacity = "^8, <=8.2.2" # latest version available on Snowflake Anaconda
29
30
  urllib3 = "<=2.1.0" # latest version available on Snowflake Anaconda
30
31
  wheel = "<=0.41.2" # latest version available on Snowflake Anaconda
31
32
 
@@ -40,6 +40,7 @@ from snowflake.connector.pandas_tools import write_pandas
40
40
  from snowflake.connector.version import VERSION
41
41
  from snowflake.snowpark import Session
42
42
  from snowflake.snowpark.functions import col
43
+ from tenacity import Retrying, stop_after_attempt, wait_fixed, retry_if_exception_message
43
44
 
44
45
  from .logging import OmnataPluginLogHandler
45
46
 
@@ -690,9 +691,8 @@ class OutboundSyncRequest(SyncRequest):
690
691
  logger.info("applying results to table")
691
692
  # use a random table name with a random string to avoid collisions
692
693
  with self._snowflake_query_lock:
693
- attempts_remaining = 12
694
- while attempts_remaining > 0:
695
- try:
694
+ for attempt in Retrying(stop=stop_after_attempt(30),wait=wait_fixed(2),reraise=True,retry=retry_if_exception_message(match=".*is being committed.*")):
695
+ with attempt:
696
696
  success, nchunks, nrows, _ = write_pandas(
697
697
  conn=self._session._conn._cursor.connection, # pylint: disable=protected-access
698
698
  df=self._preprocess_results_dataframe(results_df),
@@ -707,18 +707,6 @@ class OutboundSyncRequest(SyncRequest):
707
707
  logger.info(
708
708
  f"Wrote {nrows} rows and {nchunks} chunks to table {self._full_results_table_name}"
709
709
  )
710
- return
711
- except Exception as e:
712
- if 'is being committed' not in str(e):
713
- raise e
714
- logger.error(
715
- f"Transaction clash writing results to table {self._full_results_table_name}: {e}"
716
- )
717
- attempts_remaining -= 1
718
- time.sleep(5)
719
- raise ValueError(
720
- f"Failed to write results to table {self._full_results_table_name} after {attempts_remaining} attempts"
721
- )
722
710
 
723
711
  def __dataframe_wrapper(
724
712
  self, data_frame: pandas.DataFrame, render_jinja: bool = True
@@ -1327,9 +1315,8 @@ class InboundSyncRequest(SyncRequest):
1327
1315
  """
1328
1316
  if len(results_df) > 0:
1329
1317
  with self._snowflake_query_lock:
1330
- attempts_remaining = 12
1331
- while attempts_remaining > 0:
1332
- try:
1318
+ for attempt in Retrying(stop=stop_after_attempt(30),wait=wait_fixed(2),reraise=True,retry=retry_if_exception_message(match=".*is being committed.*")):
1319
+ with attempt:
1333
1320
  logger.info(
1334
1321
  f"Applying {len(results_df)} results to {self._full_results_table_name}"
1335
1322
  )
@@ -1358,18 +1345,6 @@ class InboundSyncRequest(SyncRequest):
1358
1345
  # )
1359
1346
  for stream_name in stream_names:
1360
1347
  self._results_exist[stream_name] = True
1361
- return
1362
- except Exception as e:
1363
- if 'is being committed' not in str(e):
1364
- raise e
1365
- logger.error(
1366
- f"Transaction clash writing results to table {self._full_results_table_name}: {e}"
1367
- )
1368
- attempts_remaining -= 1
1369
- time.sleep(5)
1370
- raise ValueError(
1371
- f"Failed to write results to table {self._full_results_table_name} after {attempts_remaining} attempts"
1372
- )
1373
1348
  else:
1374
1349
  logger.info("Results dataframe is empty, not applying")
1375
1350
 
@@ -1387,9 +1362,8 @@ class InboundSyncRequest(SyncRequest):
1387
1362
  """
1388
1363
  if len(results_df) > 0:
1389
1364
  with self._snowflake_query_lock:
1390
- attempts_remaining = 12
1391
- while attempts_remaining > 0:
1392
- try:
1365
+ for attempt in Retrying(stop=stop_after_attempt(30),wait=wait_fixed(2),reraise=True,retry=retry_if_exception_message(match=".*is being committed.*")):
1366
+ with attempt:
1393
1367
  logger.info(
1394
1368
  f"Applying {len(results_df)} criteria deletes to {self._criteria_deletes_table_name}"
1395
1369
  )
@@ -1409,17 +1383,6 @@ class InboundSyncRequest(SyncRequest):
1409
1383
  f"Wrote {nrows} rows and {nchunks} chunks to table {self._criteria_deletes_table_name}"
1410
1384
  )
1411
1385
  return
1412
- except Exception as e:
1413
- if 'is being committed' not in str(e):
1414
- raise e
1415
- logger.error(
1416
- f"Transaction clash writing results to table {self._full_results_table_name}: {e}"
1417
- )
1418
- attempts_remaining -= 1
1419
- time.sleep(5)
1420
- raise ValueError(
1421
- f"Failed to write results to table {self._full_results_table_name} after {attempts_remaining} attempts"
1422
- )
1423
1386
  else:
1424
1387
  logger.info("Results dataframe is empty, not applying")
1425
1388