From 322fe96968f9d2fd1be7aa8c68ea7fe20e88e0fd Mon Sep 17 00:00:00 2001 From: Marshall Jones Date: Tue, 22 Mar 2022 13:02:05 -0700 Subject: [PATCH] Allow specifying a configurable amount of time between retries --- redashAPI/client.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/redashAPI/client.py b/redashAPI/client.py index 477bfac..0d6ae54 100644 --- a/redashAPI/client.py +++ b/redashAPI/client.py @@ -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}") @@ -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}')