This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
commit e02dcecb0ac6c852a4077cae1df210becac64ab3 Author: qiye <[email protected]> AuthorDate: Thu May 23 16:04:06 2024 +0800 [optimize](regression)Add retry for curl request (#35260) Co-authored-by: Luennng <[email protected]> --- .../plugins/plugin_curl_requester.groovy | 32 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/regression-test/plugins/plugin_curl_requester.groovy b/regression-test/plugins/plugin_curl_requester.groovy index 7ea6f438fb7..6c4bc86270f 100644 --- a/regression-test/plugins/plugin_curl_requester.groovy +++ b/regression-test/plugins/plugin_curl_requester.groovy @@ -32,13 +32,37 @@ Suite.metaClass.curl = { String method, String url /* param */-> } Integer timeout = 10; // 10 seconds; + Integer maxRetries = 10; // Maximum number of retries + Integer retryCount = 0; // Current retry count + Integer sleepTime = 5000; // Sleep time in milliseconds String cmd = String.format("curl --max-time %d -X %s %s", timeout, method, url).toString() logger.info("curl cmd: " + cmd) - def process = cmd.execute() - int code = process.waitFor() - String err = IOGroovyMethods.getText(new BufferedReader(new InputStreamReader(process.getErrorStream()))) - String out = process.getText() + def process + int code + String err + String out + + while (retryCount < maxRetries) { + process = cmd.execute() + code = process.waitFor() + err = IOGroovyMethods.getText(new BufferedReader(new InputStreamReader(process.getErrorStream()))) + out = process.getText() + + // If the command was successful, break the loop + if (code == 0) { + break + } + + // If the command was not successful, increment the retry count, sleep for a while and try again + retryCount++ + sleep(sleepTime) + } + + // If the command was not successful after maxRetries attempts, log the failure and return the result + if (code != 0) { + logger.error("Command curl failed after " + maxRetries + " attempts. code: " + code + ", err: " + err) + } return [code, out, err] } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
