Skip to content

Commit caf8e1b

Browse files
committed
Add tenancity retries
1 parent 3aac82b commit caf8e1b

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

text_2_sql/text_2_sql_core/src/text_2_sql_core/data_dictionary/data_dictionary_creator.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import re
1717
import networkx as nx
1818
from text_2_sql_core.utils.database import DatabaseEngine
19+
from tenacity import retry, stop_after_attempt, wait_exponential
1920

2021
logging.basicConfig(level=logging.INFO)
2122

@@ -272,6 +273,9 @@ def extract_distinct_values_sql_query(
272273
"""
273274
return f"""SELECT DISTINCT {column.name} FROM {entity.entity} ORDER BY {column.name} DESC;"""
274275

276+
@retry(
277+
stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=1, max=10)
278+
)
275279
async def query_entities(
276280
self, sql_query: str, cast_to: any = None
277281
) -> list[EntityItem]:
@@ -565,6 +569,9 @@ async def extract_columns_with_definitions(
565569

566570
return columns
567571

572+
@retry(
573+
stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=1, max=10)
574+
)
568575
async def send_request_to_llm(self, system_prompt: str, input: str):
569576
"""A method to use GPT to generate a definition for an entity.
570577

text_2_sql/text_2_sql_core/src/text_2_sql_core/data_dictionary/databricks_data_dictionary_creator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import logging
77
import os
88
from text_2_sql_core.utils.database import DatabaseEngine
9+
from tenacity import retry, stop_after_attempt, wait_exponential
910

1011

1112
class DatabricksDataDictionaryCreator(DataDictionaryCreator):
@@ -99,6 +100,9 @@ def extract_entity_relationships_sql_query(self) -> str:
99100
EntitySchema, Entity, ForeignEntitySchema, ForeignEntity;
100101
"""
101102

103+
@retry(
104+
stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=1, max=10)
105+
)
102106
async def query_entities(self, sql_query: str, cast_to: any = None) -> list[dict]:
103107
"""
104108
A method to query a Databricks SQL endpoint for entities.

text_2_sql/text_2_sql_core/src/text_2_sql_core/data_dictionary/snowflake_data_dictionary_creator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88

99
from text_2_sql_core.utils.database import DatabaseEngine
10+
from tenacity import retry, stop_after_attempt, wait_exponential
1011

1112

1213
class SnowflakeDataDictionaryCreator(DataDictionaryCreator):
@@ -75,6 +76,9 @@ def extract_entity_relationships_sql_query(self) -> str:
7576
EntitySchema, Entity, ForeignEntitySchema, ForeignEntityConstraint;
7677
"""
7778

79+
@retry(
80+
stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=1, max=10)
81+
)
7882
async def query_entities(
7983
self, sql_query: str, cast_to: any = None
8084
) -> list[EntityItem]:

0 commit comments

Comments
 (0)