-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract retry methods of API calling (#590)
- Loading branch information
1 parent
04ec4ea
commit 7e7a1ce
Showing
3 changed files
with
155 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
gradle_plugin/src/main/groovy/com/microsoft/hydralab/utils/FlowUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.hydralab.utils; | ||
|
||
import okhttp3.Response; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
/** | ||
* @author Li Shen | ||
* @date 9/11/2023 | ||
*/ | ||
|
||
public class FlowUtil { | ||
public static Response httpRetryAndSleepWhenException(int count, int sleepSeconds, Callable<Response> predicate) throws Exception { | ||
Response res = null; | ||
Exception toThrow = null; | ||
while (count > 0) { | ||
try { | ||
res = predicate.call(); | ||
return res; | ||
} catch (Exception e) { | ||
toThrow = e; | ||
} | ||
CommonUtils.safeSleep(sleepSeconds * 1000L); | ||
count--; | ||
} | ||
if (toThrow != null) { | ||
throw toThrow; | ||
} | ||
return res; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters