Improve retrying logic and refactor the code

remotes/1725563413541109883/master
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())) {
if (retryCount > 0) {
try { try {
retryTime = retryTime * CONNECTION_RETRY_FACTOR; retryTime = retryTime * CONNECTION_RETRY_FACTOR;
Thread.sleep(retryTime); Thread.sleep(retryTime);
} catch (InterruptedException te) { } catch (InterruptedException te) {
//do nothing. //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