Skip to content

Commit 4f5a888

Browse files
committed
add --async_api_timeout to opengrok-sync
allow to propagate the async API timeout to CommandSequence
1 parent 519c2ab commit 4f5a888

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

tools/src/main/python/opengrok_tools/mirror.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def main():
121121
help='Set response timeout in seconds '
122122
'for RESTful API calls')
123123
parser.add_argument('--async_api_timeout', type=int, default=300,
124-
help='Set timeout in seconds for asynchronous RESTful API calls')
124+
help='Set timeout in seconds for asynchronous REST API calls')
125125

126126
try:
127127
args = parser.parse_args()

tools/src/main/python/opengrok_tools/sync.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def worker(base):
6969

7070
def do_sync(loglevel, commands, cleanup, dirs_to_process, ignore_errors,
7171
uri, numworkers, driveon=False, print_output=False, logger=None,
72-
http_headers=None, timeout=None):
72+
http_headers=None, timeout=None, api_timeout=None):
7373
"""
7474
Process the list of directories in parallel.
7575
:param logger: logger to be used in this function
@@ -86,6 +86,7 @@ def do_sync(loglevel, commands, cleanup, dirs_to_process, ignore_errors,
8686
:param logger: optional logger
8787
:param http_headers: optional dictionary of HTTP headers
8888
:param timeout: optional timeout in seconds for API call response
89+
:param api_timeout: optional timeout in seconds for async API call duration
8990
:return SUCCESS_EXITVAL on success, FAILURE_EXITVAL on error
9091
"""
9192

@@ -156,6 +157,8 @@ def main():
156157
parser.add_argument('--api_timeout', type=int, default=3,
157158
help='Set response timeout in seconds'
158159
'for RESTful API calls')
160+
parser.add_argument('--async_api_timeout', type=int, default=300,
161+
help='Set timeout in seconds for asynchronous REST API calls')
159162
add_http_headers(parser)
160163

161164
try:
@@ -275,7 +278,8 @@ def main():
275278
dirs_to_process,
276279
ignore_errors, uri, args.workers,
277280
driveon=args.driveon, http_headers=headers,
278-
timeout=args.api_timeout)
281+
timeout=args.api_timeout,
282+
api_timeout=args.async_api_timeout)
279283
except CommandConfigurationException as exc:
280284
logger.error("Invalid configuration: {}".format(exc))
281285
return FAILURE_EXITVAL
@@ -289,7 +293,8 @@ def main():
289293
dirs_to_process,
290294
ignore_errors, uri, args.workers,
291295
driveon=args.driveon, http_headers=headers,
292-
timeout=args.api_timeout)
296+
timeout=args.api_timeout,
297+
api_timeout=args.async_api_timeout)
293298
except CommandConfigurationException as exc:
294299
logger.error("Invalid configuration: {}".format(exc))
295300
return FAILURE_EXITVAL

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class CommandSequenceBase:
7272

7373
def __init__(self, name, commands, loglevel=logging.INFO, cleanup=None,
7474
driveon=False, url=None, env=None, http_headers=None,
75-
api_timeout=None):
75+
api_timeout=None, async_api_timeout=None):
7676
self.name = name
7777

7878
if commands is None:
@@ -99,6 +99,7 @@ def __init__(self, name, commands, loglevel=logging.INFO, cleanup=None,
9999
self.env = env
100100
self.http_headers = http_headers
101101
self.api_timeout = api_timeout
102+
self.async_api_timeout = async_api_timeout
102103

103104
self.url = url
104105

@@ -132,7 +133,8 @@ def __init__(self, base):
132133
cleanup=base.cleanup, driveon=base.driveon,
133134
url=base.url, env=base.env,
134135
http_headers=base.http_headers,
135-
api_timeout=base.api_timeout)
136+
api_timeout=base.api_timeout,
137+
async_api_timeout=base.async_api_timeout)
136138

137139
self.logger = logging.getLogger(__name__)
138140
self.logger.setLevel(base.loglevel)
@@ -169,7 +171,9 @@ def run(self):
169171
call_rest_api(command.get(CALL_PROPERTY),
170172
{PROJECT_SUBST: self.name,
171173
URL_SUBST: self.url},
172-
self.http_headers, self.api_timeout)
174+
self.http_headers,
175+
self.api_timeout,
176+
self.async_api_timeout)
173177
except RequestException as e:
174178
self.logger.error("REST API call {} failed: {}".
175179
format(command, e))
@@ -229,7 +233,9 @@ def run_cleanup(self):
229233
call_rest_api(cleanup_cmd.get(CALL_PROPERTY),
230234
{PROJECT_SUBST: self.name,
231235
URL_SUBST: self.url},
232-
self.http_headers, self.api_timeout)
236+
self.http_headers,
237+
self.api_timeout,
238+
self.async_api_timeout)
233239
except RequestException as e:
234240
self.logger.error("API call {} failed: {}".
235241
format(cleanup_cmd, e))

0 commit comments

Comments
 (0)