Skip to content

Commit cc7022c

Browse files
committed
cleanup timeout handling
1 parent 24a3d81 commit cc7022c

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

tools/src/main/python/opengrok_tools/utils/opengrok.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919

2020
#
21-
# Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
21+
# Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2222
#
2323

2424
import urllib.parse
@@ -191,7 +191,7 @@ def delete_project(logger, project, uri, headers=None, timeout=None, api_timeout
191191
r = do_api_call('DELETE', get_uri(uri, 'api', 'v1', 'projects',
192192
urllib.parse.quote_plus(project)),
193193
headers=headers, timeout=timeout, api_timeout=api_timeout)
194-
if r is None or r.status != 204:
194+
if r is None or r.status_code != 204:
195195
logger.error(f"could not delete project '{project}' in web application")
196196
return False
197197
except Exception as exception:

tools/src/main/python/opengrok_tools/utils/restful.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919

2020
#
21-
# Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
21+
# Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
2222
#
2323

2424
import json
@@ -48,6 +48,7 @@ def wait_for_async_api(response, api_timeout, headers=None, timeout=None):
4848
if location_uri is None:
4949
raise Exception(f"no Location header in {response}")
5050

51+
start_time = time.time()
5152
for _ in range(api_timeout):
5253
logger.debug(f"GET API call: {location_uri}, timeout {timeout} seconds and headers: {headers}")
5354
response = requests.get(location_uri, headers=headers, proxies=get_proxies(location_uri), timeout=timeout)
@@ -60,7 +61,8 @@ def wait_for_async_api(response, api_timeout, headers=None, timeout=None):
6061
break
6162

6263
if response.status_code == 202:
63-
logger.warn(f"API request still not completed: {response}")
64+
wait_time = time.time() - start_time
65+
logger.warn(f"API request still not completed after {int(wait_time)} seconds: {response}")
6466
return response
6567

6668
logger.debug(f"DELETE API call to {location_uri}")
@@ -69,7 +71,7 @@ def wait_for_async_api(response, api_timeout, headers=None, timeout=None):
6971
return response
7072

7173

72-
def do_api_call(verb, uri, params=None, headers=None, data=None, timeout=None, api_timeout=None):
74+
def do_api_call(verb, uri, params=None, headers=None, data=None, timeout=60, api_timeout=300):
7375
"""
7476
Perform an API call. Will raise an exception if the request fails.
7577
:param verb: string holding HTTP verb
@@ -90,14 +92,8 @@ def do_api_call(verb, uri, params=None, headers=None, data=None, timeout=None, a
9092
if handler is None or not callable(handler):
9193
raise Exception('Unknown HTTP verb: {}'.format(verb))
9294

93-
if timeout is None:
94-
timeout = 60
95-
96-
if api_timeout is None:
97-
api_timeout = 300
98-
99-
logger.debug("{} API call: {} with data '{}', timeout {} seconds and headers: {}".
100-
format(verb, uri, data, timeout, headers))
95+
logger.debug("{} API call: {} with data '{}', connect timeout {} seconds, API timeout {} seconds and headers: {}".
96+
format(verb, uri, data, timeout, api_timeout, headers))
10197
r = handler(
10298
uri,
10399
data=data,

0 commit comments

Comments
 (0)