Skip to content

Commit

Permalink
Merge pull request #78 from datafuselabs/feat/enlarge-retry-timeout
Browse files Browse the repository at this point in the history
feat: enlarge retry time for WarehouseTimeoutException
  • Loading branch information
hantmac authored Jun 12, 2024
2 parents a4018c9 + bf70dbc commit fd4a1d3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion databend_py/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_description(self):
def disconnect(self):
self.client_session = dict()

@retry(times=5, exceptions=WarehouseTimeoutException)
@retry(times=10, exceptions=WarehouseTimeoutException)
def do_query(self, url, query_sql):
response = self.requests_session.post(url,
data=json.dumps(query_sql),
Expand Down
7 changes: 4 additions & 3 deletions databend_py/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from databend_py.errors import WarehouseTimeoutException


# retry in 550s for WarehouseTimeoutException
def retry(times, exceptions):
"""
Retry Decorator
Expand All @@ -15,16 +16,16 @@ def retry(times, exceptions):

def decorator(func):
def newfn(*args, **kwargs):
attempt = 0
while attempt < times:
attempt = 1
while attempt <= times:
try:
return func(*args, **kwargs)
except exceptions:
print(
'Exception thrown when attempting to run %s, attempt '
'%d of %d' % (func, attempt, times)
)
time.sleep(attempt * 5)
time.sleep(attempt * 10)
attempt += 1
return func(*args, **kwargs)

Expand Down

0 comments on commit fd4a1d3

Please sign in to comment.