diff --git a/scripts/retry.js b/scripts/retry.js index 59a0b50..03a9d29 100644 --- a/scripts/retry.js +++ b/scripts/retry.js @@ -1,24 +1,21 @@ /** - * Retry a function with exponential backoff. + * Retry a function with exponential backoff (4 attempts, 2s/4s/8s waits). * * @param {Function} fn - async function to retry * @param {string} label - descriptive label for log messages - * @param {object} [options] - * @param {number} [options.maxAttempts=4] - total attempts before giving up - * @param {number} [options.baseDelay=1000] - base delay in ms (doubled each attempt) - * @param {object} [options.core] - GitHub Actions core module for warnings (falls back to console) + * @param {object} options + * @param {object} options.core - GitHub Actions core module for warnings * @returns {Promise<*>} result of fn() */ -async function retryWithBackoff(fn, label, { maxAttempts = 4, baseDelay = 1000, core = null } = {}) { - const warn = core ? (msg) => core.warning(msg) : console.warn; - +async function retryWithBackoff(fn, label, { core }) { + const maxAttempts = 4; for (let attempt = 1; attempt <= maxAttempts; attempt++) { try { return await fn(); } catch (err) { if (attempt === maxAttempts) throw err; - const delay = Math.pow(2, attempt) * baseDelay; - warn(`${label} failed (attempt ${attempt}/${maxAttempts}): ${err.message}. Retrying in ${delay}ms...`); + const delay = Math.pow(2, attempt) * 1000; + core.warning(`${label} failed (attempt ${attempt}/${maxAttempts}): ${err.message}. Retrying in ${delay}ms...`); await new Promise((r) => setTimeout(r, delay)); } }