Improve retrying logic and refactor the code

secure-folder-policy
Rajitha Kumara 3 months ago
parent c6f65d9675
commit db1f12ea88

@ -71,14 +71,16 @@ public class APIPublisherStartupHandler implements ServerStartupObserver {
publisher = APIPublisherDataHolder.getInstance().getApiPublisherService(); publisher = APIPublisherDataHolder.getInstance().getApiPublisherService();
int retryCount = 0; int retryCount = 0;
while (retryCount < MAX_RETRY_COUNT && (!failedAPIsStack.isEmpty() || !currentAPIsStack.isEmpty())) { while (retryCount < MAX_RETRY_COUNT && (!failedAPIsStack.isEmpty() || !currentAPIsStack.isEmpty())) {
try { if (retryCount > 0) {
retryTime = retryTime * CONNECTION_RETRY_FACTOR; try {
Thread.sleep(retryTime); retryTime = retryTime * CONNECTION_RETRY_FACTOR;
} catch (InterruptedException te) { Thread.sleep(retryTime);
//do nothing. } catch (InterruptedException te) {
//do nothing.
}
} }
Stack<APIConfig> failedApis; Stack<APIConfig> failedApis;
if (!APIPublisherDataHolder.getInstance().getUnpublishedApis().isEmpty()) { if (!currentAPIsStack.isEmpty()) {
publishAPIs(currentAPIsStack, failedAPIsStack); publishAPIs(currentAPIsStack, failedAPIsStack);
failedApis = failedAPIsStack; failedApis = failedAPIsStack;
} else { } else {
@ -124,6 +126,13 @@ public class APIPublisherStartupHandler implements ServerStartupObserver {
log.info("Starting API publishing procedure"); log.info("Starting API publishing procedure");
} }
/**
* Publish apis provided by the API stack, if failed while publishing, then failed API will be added to
* the failed API stack
*
* @param apis Stack of APIs to publish
* @param failedStack Stack to record failed APIs
*/
private void publishAPIs(Stack<APIConfig> apis, Stack<APIConfig> failedStack) { private void publishAPIs(Stack<APIConfig> apis, Stack<APIConfig> failedStack) {
while (!apis.isEmpty()) { while (!apis.isEmpty()) {
APIConfig api = apis.pop(); APIConfig api = apis.pop();

Loading…
Cancel
Save