From fd12c153d69b83b645a18bca892254b273d5adec Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Thu, 30 Nov 2023 10:32:08 -0500 Subject: [PATCH] fix: clear pending root if detected on push --- src/datalayer/persistance.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/datalayer/persistance.js b/src/datalayer/persistance.js index bd254874..c586f71c 100644 --- a/src/datalayer/persistance.js +++ b/src/datalayer/persistance.js @@ -77,14 +77,14 @@ const clearPendingRoots = async (storeId) => { const data = response.body; if (data.success) { - return data.mirrors; + return true; } - logger.error(`FAILED GETTING MIRRORS FOR ${storeId}`); - return []; + logger.error(`Unable to clear pending root for ${storeId}`); + return false; } catch (error) { logger.error(error); - return []; + return false; } }; @@ -432,10 +432,13 @@ const pushChangeListToDataLayer = async (storeId, changelist) => { if (data.error.includes('Key already present')) { logger.info('Pending root detected, waiting 5 seconds and retrying'); - await clearPendingRoots(storeId); - attempts++; - await new Promise((resolve) => setTimeout(resolve, 5000)); - continue; // Retry + const rootsCleared = await clearPendingRoots(storeId); + + if (rootsCleared) { + attempts++; + await new Promise((resolve) => setTimeout(resolve, 5000)); + continue; // Retry + } } logger.error(