From 3a265b5c1de5186ecc38f5f59581b11eaab02892 Mon Sep 17 00:00:00 2001 From: "alon.dotan" Date: Mon, 23 Sep 2024 11:56:48 +0300 Subject: [PATCH] fix: handle 429 api rate error --- src/cargo.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/cargo.ts b/src/cargo.ts index dfca963..b86bb83 100644 --- a/src/cargo.ts +++ b/src/cargo.ts @@ -195,8 +195,19 @@ export async function saveCache() { for (const cachePath of cachePaths) { core.debug(`- ${cachePath}`); } - - await cache.saveCache(cachePaths, primaryKey); + for (let i = 1; i <= 10; i++) { + try { + return await cache.saveCache(cachePaths, primaryKey); + } + catch(error) { + const errStr = `${error}` + if (errStr.includes("Cache service responded with 429 during upload chunk")) { + core.info('Failed to upload cache, got rate limit error, waiting 30 seconds.'); + await new Promise(f => setTimeout(f, 30000)); + } + } + } + throw Error("Failed to upload cache.") } export async function restoreCache() {