From 3dde82f08735bc5b9923cac82542fc7ffb7805c9 Mon Sep 17 00:00:00 2001 From: Jeroen Maes Date: Mon, 15 Apr 2024 17:21:08 +0200 Subject: [PATCH 1/4] Warn, don't fail, when an API is not found --- tools/code/publisher/ProductApi.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/code/publisher/ProductApi.cs b/tools/code/publisher/ProductApi.cs index df101056..463740ad 100644 --- a/tools/code/publisher/ProductApi.cs +++ b/tools/code/publisher/ProductApi.cs @@ -179,6 +179,12 @@ private static async ValueTask Put(ApiName apiName, ProductUri productUri, PutRe throw; } } + catch (HttpRequestException httpRequestException) when (httpRequestException.Message.Contains("API not found")) + { + logger.LogWarning("API not found, the API will not be added to the Product."); + + return; + } } } From c1ba8a0c903b4064c6df2c667997e89b22efa13b Mon Sep 17 00:00:00 2001 From: Jeroen Maes Date: Tue, 16 Apr 2024 07:56:28 +0200 Subject: [PATCH 2/4] Add retry --- tools/code/publisher/ProductApi.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/code/publisher/ProductApi.cs b/tools/code/publisher/ProductApi.cs index 463740ad..af7606c3 100644 --- a/tools/code/publisher/ProductApi.cs +++ b/tools/code/publisher/ProductApi.cs @@ -181,9 +181,19 @@ private static async ValueTask Put(ApiName apiName, ProductUri productUri, PutRe } catch (HttpRequestException httpRequestException) when (httpRequestException.Message.Contains("API not found")) { - logger.LogWarning("API not found, the API will not be added to the Product."); - - return; + retryCount++; + if (retryCount <= 3) + { + // Log the retry attempt + logger.LogWarning("Retrying API put operation for {apiName}. Retry attempt: {retryCount}", apiName, retryCount); + // Wait for a certain duration before retrying + await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, retryCount)), cancellationToken); + } + else + { + // Retry limit reached, log as warning + logger.LogWarning("API {apiName} not found, the API will not be added to product in the target environment.", apiName); + } } } } From fe2b6a78941d588a375e8ad3ca02c354e64bcc6b Mon Sep 17 00:00:00 2001 From: Jeroen Maes Date: Tue, 16 Apr 2024 10:54:36 +0200 Subject: [PATCH 3/4] Fix endless loop... --- tools/code/publisher/ProductApi.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/code/publisher/ProductApi.cs b/tools/code/publisher/ProductApi.cs index af7606c3..6a10bda3 100644 --- a/tools/code/publisher/ProductApi.cs +++ b/tools/code/publisher/ProductApi.cs @@ -193,6 +193,9 @@ private static async ValueTask Put(ApiName apiName, ProductUri productUri, PutRe { // Retry limit reached, log as warning logger.LogWarning("API {apiName} not found, the API will not be added to product in the target environment.", apiName); + + // End retry without exception + return; } } } From bc101f3fabe0b7048a48a8147d3e56f1eb209430 Mon Sep 17 00:00:00 2001 From: Jeroen Maes Date: Tue, 16 Apr 2024 11:03:14 +0200 Subject: [PATCH 4/4] improve log message --- tools/code/publisher/ProductApi.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/code/publisher/ProductApi.cs b/tools/code/publisher/ProductApi.cs index 6a10bda3..0dda05b0 100644 --- a/tools/code/publisher/ProductApi.cs +++ b/tools/code/publisher/ProductApi.cs @@ -192,7 +192,7 @@ private static async ValueTask Put(ApiName apiName, ProductUri productUri, PutRe else { // Retry limit reached, log as warning - logger.LogWarning("API {apiName} not found, the API will not be added to product in the target environment.", apiName); + logger.LogWarning("API {apiName} not found, the API is NOT added to product in the target environment.", apiName); // End retry without exception return;