Skip to content

Commit

Permalink
Add timeout to table creation
Browse files Browse the repository at this point in the history
  • Loading branch information
blythed committed Oct 23, 2024
1 parent a52594c commit 70d54d6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

**Before you create a Pull Request, remember to update the Changelog with your changes.**

## Changes Since Last Release
## Changes Since Last Release

#### Changed defaults / behaviours

Expand Down
27 changes: 26 additions & 1 deletion superduper/base/datalayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def _insert(
:param insert: The insert query object specifying the data to be inserted.
:param refresh: Boolean indicating whether to refresh the task group on insert.
:param datatypes: List of datatypes in the insert documents.
:param auto_schema: Toggle to False to switch off automatic schema creation.
"""
for e in datatypes:
self.add(e)
Expand All @@ -280,7 +281,31 @@ def _insert(
)
if auto_schema and self.cfg.auto_schema:
self._auto_create_table(insert.table, insert.documents)
# <--- need to wait here --->

timeout = 5

import time

start = time.time()

exists = False
while time.time() - start < timeout:
try:
assert insert.table in self.show(
'table'
), f'{insert.table} not found, retrying...'
exists = True
except AssertionError as e:
logging.warn(str(e))
time.sleep(0.25)
continue
break

if not exists:
raise TimeoutError(
f'{insert.table} not found after {timeout} seconds'
' table auto creation likely has failed or is stalling...'
)

inserted_ids = insert.do_execute(self)

Expand Down

0 comments on commit 70d54d6

Please sign in to comment.