Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying a configurable amount of time between retries #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions redashAPI/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
from datetime import datetime

class RedashAPIClient:
def __init__(self, api_key: str, host: str="http://localhost:5000"):
def __init__(self, api_key: str, host: str="http://localhost:5000", ms_between_retries: int=200):
self.api_key = api_key
self.host = host

self.s = requests.Session()
self.s.headers.update({"Authorization": f"Key {api_key}"})
self.ms_between_retries = ms_between_retries

def get(self, uri: str):
res = self.s.get(f"{self.host}/api/{uri}")
Expand Down Expand Up @@ -120,7 +121,7 @@ def query_and_wait_result(self, ds_id: int, query: str, timeout: int=60):
if (datetime.now() - start).total_seconds() > timeout:
raise Exception('Polling timeout.')

time.sleep(0.2)
time.sleep(self.ms_between_retries / 1000.0)

return self.get(f'query_results/{query_result_id}')

Expand Down