Skip to content

Commit

Permalink
[FIX] Adjusted timeout for correct function
Browse files Browse the repository at this point in the history
  • Loading branch information
DESm1th committed Sep 15, 2023
1 parent e742cc3 commit c3ca436
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions datman/xnat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,12 +1048,14 @@ def _get_xnat_stream(self, url, filename, retries=3, timeout=300):
logger.error("Failed writing to file")
raise (e)

def _make_xnat_query(self, url, retries=3):
def _make_xnat_query(self, url, retries=3, timeout=150):
try:
response = self.session.get(url, timeout=30)
response = self.session.get(url, timeout=timeout)
except requests.exceptions.Timeout as e:
if retries > 0:
return self._make_xnat_query(url, retries=retries - 1)
return self._make_xnat_query(
url, retries=retries - 1, timeout=timeout * 2
)
else:
logger.error(f"Xnat server timed out getting url {url}")
raise e
Expand All @@ -1062,7 +1064,7 @@ def _make_xnat_query(self, url, retries=3):
# possibly the session has timed out
logger.info("Session may have expired, resetting")
self.open_session()
response = self.session.get(url, timeout=30)
response = self.session.get(url, timeout=timeout)

if response.status_code == 404:
logger.info(
Expand All @@ -1075,22 +1077,20 @@ def _make_xnat_query(self, url, retries=3):
response.raise_for_status()
return response.json()

def _make_xnat_xml_query(self, url, retries=3, timeout=150):
def _make_xnat_xml_query(self, url, retries=3):
try:
response = self.session.get(url, timeout=timeout)
response = self.session.get(url)
except requests.exceptions.Timeout as e:
if retries > 0:
return self._make_xnat_xml_query(
url, retries=retries - 1, timeout=timeout * 2
)
return self._make_xnat_xml_query(url, retries=retries - 1)
else:
raise e

if response.status_code == 401:
# possibly the session has timed out
logger.info("Session may have expired, resetting")
self.open_session()
response = self.session.get(url, timeout=timeout)
response = self.session.get(url)

if response.status_code == 404:
logger.info(f"No records returned from xnat server to query {url}")
Expand Down

0 comments on commit c3ca436

Please sign in to comment.