Skip to content
Snippets Groups Projects
Commit 849fc4df authored by Carsten Hinz's avatar Carsten Hinz
Browse files

added waiting time before restarting a request

parent 7cce3ae8
Branches
Tags
1 merge request!11Creation of first beta release version
...@@ -257,7 +257,8 @@ class Connection: ...@@ -257,7 +257,8 @@ class Connection:
This function catches possible connection issues and continues to This function catches possible connection issues and continues to
""" """
status_endpoint = self.get_status_endpoint(query_options) status_endpoint = self.get_status_endpoint(query_options)
nRestart=0
waitRestart = 300
for i, wait_time in enumerate(self.wait_seconds): for i, wait_time in enumerate(self.wait_seconds):
logger.info(f"try: {i+1}, wait_time: {wait_time}") logger.info(f"try: {i+1}, wait_time: {wait_time}")
response = self.wait_and_get(status_endpoint, wait_secs=wait_time) response = self.wait_and_get(status_endpoint, wait_secs=wait_time)
...@@ -269,7 +270,8 @@ class Connection: ...@@ -269,7 +270,8 @@ class Connection:
self.printExecption(e, response) self.printExecption(e, response)
#a Status Code 500 seems indicated an aborted request -> restart the request and continue with new status endpoint #a Status Code 500 seems indicated an aborted request -> restart the request and continue with new status endpoint
if e.response.status_code == 500: if e.response.status_code == 500:
logger.warning("Received internal server error. Restarting request.") logger.warning(f"Received internal server error. Restarting request in {waitRestart}s.")
time.sleep(waitRestart)
self.cache.remove(query_options.cache_key) self.cache.remove(query_options.cache_key)
status_endpoint = self.get_status_endpoint(query_options) status_endpoint = self.get_status_endpoint(query_options)
else: else:
...@@ -281,7 +283,7 @@ class Connection: ...@@ -281,7 +283,7 @@ class Connection:
return response return response
else: else:
raise RuntimeError( raise RuntimeError(
f"No data available after {sum(self.wait_seconds) / 60} minutes. retry later." f"No data available after {sum(self.wait_seconds) / 60 + nRestart*waitRestart / 60} minutes. retry later."
) )
def get_status_endpoint(self, query_options: QueryOptions) -> str: def get_status_endpoint(self, query_options: QueryOptions) -> str:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment