From db1f12ea8882cd84db9cbdd40c8f0012720552db Mon Sep 17 00:00:00 2001 From: Rajitha Kumara Date: Thu, 15 Aug 2024 01:13:20 +0530 Subject: [PATCH] Improve retrying logic and refactor the code --- .../publisher/APIPublisherStartupHandler.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherStartupHandler.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherStartupHandler.java index fe2f6ba0bc..796a31d957 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherStartupHandler.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherStartupHandler.java @@ -71,14 +71,16 @@ public class APIPublisherStartupHandler implements ServerStartupObserver { publisher = APIPublisherDataHolder.getInstance().getApiPublisherService(); int retryCount = 0; while (retryCount < MAX_RETRY_COUNT && (!failedAPIsStack.isEmpty() || !currentAPIsStack.isEmpty())) { - try { - retryTime = retryTime * CONNECTION_RETRY_FACTOR; - Thread.sleep(retryTime); - } catch (InterruptedException te) { - //do nothing. + if (retryCount > 0) { + try { + retryTime = retryTime * CONNECTION_RETRY_FACTOR; + Thread.sleep(retryTime); + } catch (InterruptedException te) { + //do nothing. + } } Stack failedApis; - if (!APIPublisherDataHolder.getInstance().getUnpublishedApis().isEmpty()) { + if (!currentAPIsStack.isEmpty()) { publishAPIs(currentAPIsStack, failedAPIsStack); failedApis = failedAPIsStack; } else { @@ -124,6 +126,13 @@ public class APIPublisherStartupHandler implements ServerStartupObserver { 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 apis, Stack failedStack) { while (!apis.isEmpty()) { APIConfig api = apis.pop();