omnata-plugin-runtime 0.4.0a87__py3-none-any.whl → 0.4.0a89__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -350,12 +350,13 @@ class SyncRequest(ABC):
350
350
  update_rate_limit_result = self._plugin_message(
351
351
  PluginMessageRateLimitState(rate_limit_state=self.rate_limit_state_this_sync_and_branch)
352
352
  )
353
- sync_id:int = update_rate_limit_result["sync_id"]
354
- sync_branch_name:str = update_rate_limit_result["sync_branch_name"]
355
- latest_state:Dict[int,Dict[str,Dict[str,RateLimitState]]] = parse_obj_as(Dict[int,Dict[str,Dict[str,RateLimitState]]],update_rate_limit_result["latest_state"])
356
- (rate_limit_state_all, rate_limit_state_this_branch) = RateLimitState.collapse(latest_state,sync_id, sync_branch_name)
357
- self.rate_limit_state_all = rate_limit_state_all
358
- self.rate_limit_state_this_sync_and_branch = rate_limit_state_this_branch
353
+ if update_rate_limit_result is not None:
354
+ sync_id:int = update_rate_limit_result["sync_id"]
355
+ sync_branch_name:str = update_rate_limit_result["sync_branch_name"]
356
+ latest_state:Dict[int,Dict[str,Dict[str,RateLimitState]]] = parse_obj_as(Dict[int,Dict[str,Dict[str,RateLimitState]]],update_rate_limit_result["latest_state"])
357
+ (rate_limit_state_all, rate_limit_state_this_branch) = RateLimitState.collapse(latest_state,sync_id, sync_branch_name)
358
+ self.rate_limit_state_all = rate_limit_state_all
359
+ self.rate_limit_state_this_sync_and_branch = rate_limit_state_this_branch
359
360
  else:
360
361
  logger.info("No rate limit state to update")
361
362
 
@@ -689,19 +690,34 @@ class OutboundSyncRequest(SyncRequest):
689
690
  logger.info("applying results to table")
690
691
  # use a random table name with a random string to avoid collisions
691
692
  with self._snowflake_query_lock:
692
- success, nchunks, nrows, _ = write_pandas(
693
- conn=self._session._conn._cursor.connection, # pylint: disable=protected-access
694
- df=self._preprocess_results_dataframe(results_df),
695
- quote_identifiers=False,
696
- table_name=self._full_results_table_name,
697
- auto_create_table=False
698
- )
699
- if not success:
700
- raise ValueError(
701
- f"Failed to write results to table {self._full_results_table_name}"
702
- )
703
- logger.info(
704
- f"Wrote {nrows} rows and {nchunks} chunks to table {self._full_results_table_name}"
693
+ attempts_remaining = 12
694
+ while attempts_remaining > 0:
695
+ try:
696
+ success, nchunks, nrows, _ = write_pandas(
697
+ conn=self._session._conn._cursor.connection, # pylint: disable=protected-access
698
+ df=self._preprocess_results_dataframe(results_df),
699
+ quote_identifiers=False,
700
+ table_name=self._full_results_table_name,
701
+ auto_create_table=False
702
+ )
703
+ if not success:
704
+ raise ValueError(
705
+ f"Failed to write results to table {self._full_results_table_name}"
706
+ )
707
+ logger.info(
708
+ f"Wrote {nrows} rows and {nchunks} chunks to table {self._full_results_table_name}"
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"
705
721
  )
706
722
 
707
723
  def __dataframe_wrapper(
@@ -1307,34 +1323,49 @@ class InboundSyncRequest(SyncRequest):
1307
1323
  """
1308
1324
  if len(results_df) > 0:
1309
1325
  with self._snowflake_query_lock:
1310
- logger.info(
1311
- f"Applying {len(results_df)} results to {self._full_results_table_name}"
1312
- )
1313
- # try setting parquet engine here, since the engine parameter does not seem to make it through to the write_pandas function
1314
- success, nchunks, nrows, _ = write_pandas(
1315
- conn=self._session._conn._cursor.connection, # pylint: disable=protected-access
1316
- df=results_df,
1317
- table_name=self._full_results_table_name,
1318
- quote_identifiers=False, # already done in get_temp_table_name
1319
- # schema='INBOUND_RAW', # it seems to be ok to provide schema in the table name
1320
- table_type="transient"
1321
- )
1322
- if not success:
1323
- raise ValueError(
1324
- f"Failed to write results to table {self._full_results_table_name}"
1325
- )
1326
- logger.info(
1327
- f"Wrote {nrows} rows and {nchunks} chunks to table {self._full_results_table_name}"
1326
+ attempts_remaining = 12
1327
+ while attempts_remaining > 0:
1328
+ try:
1329
+ logger.info(
1330
+ f"Applying {len(results_df)} results to {self._full_results_table_name}"
1331
+ )
1332
+ # try setting parquet engine here, since the engine parameter does not seem to make it through to the write_pandas function
1333
+ success, nchunks, nrows, _ = write_pandas(
1334
+ conn=self._session._conn._cursor.connection, # pylint: disable=protected-access
1335
+ df=results_df,
1336
+ table_name=self._full_results_table_name,
1337
+ quote_identifiers=False, # already done in get_temp_table_name
1338
+ # schema='INBOUND_RAW', # it seems to be ok to provide schema in the table name
1339
+ table_type="transient"
1340
+ )
1341
+ if not success:
1342
+ raise ValueError(
1343
+ f"Failed to write results to table {self._full_results_table_name}"
1344
+ )
1345
+ logger.info(
1346
+ f"Wrote {nrows} rows and {nchunks} chunks to table {self._full_results_table_name}"
1347
+ )
1348
+ # temp tables aren't allowed
1349
+ # snowflake_df = self._session.create_dataframe(results_df)
1350
+ # snowflake_df.write.save_as_table(table_name=temp_table,
1351
+ # mode='append',
1352
+ # column_order='index',
1353
+ # #create_temp_table=True
1354
+ # )
1355
+ for stream_name in stream_names:
1356
+ self._results_exist[stream_name] = True
1357
+ return
1358
+ except Exception as e:
1359
+ if 'is being committed' not in str(e):
1360
+ raise e
1361
+ logger.error(
1362
+ f"Transaction clash writing results to table {self._full_results_table_name}: {e}"
1363
+ )
1364
+ attempts_remaining -= 1
1365
+ time.sleep(5)
1366
+ raise ValueError(
1367
+ f"Failed to write results to table {self._full_results_table_name} after {attempts_remaining} attempts"
1328
1368
  )
1329
- # temp tables aren't allowed
1330
- # snowflake_df = self._session.create_dataframe(results_df)
1331
- # snowflake_df.write.save_as_table(table_name=temp_table,
1332
- # mode='append',
1333
- # column_order='index',
1334
- # #create_temp_table=True
1335
- # )
1336
- for stream_name in stream_names:
1337
- self._results_exist[stream_name] = True
1338
1369
  else:
1339
1370
  logger.info("Results dataframe is empty, not applying")
1340
1371
 
@@ -1352,23 +1383,38 @@ class InboundSyncRequest(SyncRequest):
1352
1383
  """
1353
1384
  if len(results_df) > 0:
1354
1385
  with self._snowflake_query_lock:
1355
- logger.info(
1356
- f"Applying {len(results_df)} criteria deletes to {self._criteria_deletes_table_name}"
1357
- )
1358
- # try setting parquet engine here, since the engine parameter does not seem to make it through to the write_pandas function
1359
- success, nchunks, nrows, _ = write_pandas(
1360
- conn=self._session._conn._cursor.connection, # pylint: disable=protected-access
1361
- df=results_df,
1362
- table_name=self._criteria_deletes_table_name,
1363
- quote_identifiers=False, # already done in get_temp_table_name
1364
- table_type="transient"
1365
- )
1366
- if not success:
1367
- raise ValueError(
1368
- f"Failed to write results to table {self._criteria_deletes_table_name}"
1369
- )
1370
- logger.info(
1371
- f"Wrote {nrows} rows and {nchunks} chunks to table {self._criteria_deletes_table_name}"
1386
+ attempts_remaining = 12
1387
+ while attempts_remaining > 0:
1388
+ try:
1389
+ logger.info(
1390
+ f"Applying {len(results_df)} criteria deletes to {self._criteria_deletes_table_name}"
1391
+ )
1392
+ # try setting parquet engine here, since the engine parameter does not seem to make it through to the write_pandas function
1393
+ success, nchunks, nrows, _ = write_pandas(
1394
+ conn=self._session._conn._cursor.connection, # pylint: disable=protected-access
1395
+ df=results_df,
1396
+ table_name=self._criteria_deletes_table_name,
1397
+ quote_identifiers=False, # already done in get_temp_table_name
1398
+ table_type="transient"
1399
+ )
1400
+ if not success:
1401
+ raise ValueError(
1402
+ f"Failed to write results to table {self._criteria_deletes_table_name}"
1403
+ )
1404
+ logger.info(
1405
+ f"Wrote {nrows} rows and {nchunks} chunks to table {self._criteria_deletes_table_name}"
1406
+ )
1407
+ return
1408
+ except Exception as e:
1409
+ if 'is being committed' not in str(e):
1410
+ raise e
1411
+ logger.error(
1412
+ f"Transaction clash writing results to table {self._full_results_table_name}: {e}"
1413
+ )
1414
+ attempts_remaining -= 1
1415
+ time.sleep(5)
1416
+ raise ValueError(
1417
+ f"Failed to write results to table {self._full_results_table_name} after {attempts_remaining} attempts"
1372
1418
  )
1373
1419
  else:
1374
1420
  logger.info("Results dataframe is empty, not applying")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omnata-plugin-runtime
3
- Version: 0.4.0a87
3
+ Version: 0.4.0a89
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
@@ -3,10 +3,10 @@ omnata_plugin_runtime/api.py,sha256=W79CsAcl127Dzy-XVS9CzvzsbS3IigVH4QAhFFDkaXg,
3
3
  omnata_plugin_runtime/configuration.py,sha256=7cMekoY8CeZAJHpASU6tCMidF55Hzfr7CD74jtebqIY,35742
4
4
  omnata_plugin_runtime/forms.py,sha256=pw_aKVsXSz47EP8PFBI3VDwdSN5IjvZxp8JTjO1V130,18421
5
5
  omnata_plugin_runtime/logging.py,sha256=bn7eKoNWvtuyTk7RTwBS9UARMtqkiICtgMtzq3KA2V0,3272
6
- omnata_plugin_runtime/omnata_plugin.py,sha256=s9h0zqkCJYeBpKIeUQathy7gOw_0Tw-irhdBW72q2xo,105616
6
+ omnata_plugin_runtime/omnata_plugin.py,sha256=JJtpl8iKcTMgIOymkZh9yKMhZBemXQOGe8s8iJSw5Hk,108276
7
7
  omnata_plugin_runtime/plugin_entrypoints.py,sha256=D2f0Qih7KTJNXIDYkA-E55RTEK_7Jtv9ySqspWxERVA,28272
8
8
  omnata_plugin_runtime/rate_limiting.py,sha256=29Hjsr0i1rE8jERVdIFGINfQfp_kI3PDft-IM_ZxvCA,21509
9
- omnata_plugin_runtime-0.4.0a87.dist-info/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
10
- omnata_plugin_runtime-0.4.0a87.dist-info/METADATA,sha256=-yx21xGaWDk6paSBL0QfVC2JE4IiEyeV6SQiQT7KfMo,1603
11
- omnata_plugin_runtime-0.4.0a87.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
12
- omnata_plugin_runtime-0.4.0a87.dist-info/RECORD,,
9
+ omnata_plugin_runtime-0.4.0a89.dist-info/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
10
+ omnata_plugin_runtime-0.4.0a89.dist-info/METADATA,sha256=LEkEREX1mBrQoSb6abHniwlf8gZfkBicmmzhbP_Glgw,1603
11
+ omnata_plugin_runtime-0.4.0a89.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
12
+ omnata_plugin_runtime-0.4.0a89.dist-info/RECORD,,