MCPcopy
hub / github.com/vercel/next.js / retryKVOperation

Function retryKVOperation

run-tests.js:78–102  ·  view source on GitHub ↗

* Retry a KV operation with exponential backoff * @param {() => Promise<any>} operation - The async operation to retry * @param {string} operationName - Name of the operation for logging * @param {number} maxRetries - Maximum number of retries (default: 3) * @returns {Promise<any>} The result of

(operation, operationName, maxRetries = 3)

Source from the content-addressed store, hash-verified

76 * @returns {Promise<any>} The result of the operation
77 */
78async function retryKVOperation(operation, operationName, maxRetries = 3) {
79 let lastError
80 let retries = maxRetries
81
82 while (retries > 0) {
83 try {
84 return await operation()
85 } catch (err) {
86 lastError = err
87 retries--
88 if (retries > 0) {
89 const delay = (maxRetries - retries + 1) * 5 // 5s, 10s, 15s backoff
90 console.log(
91 `KV ${operationName} failed, retrying in ${delay}s. Error:`,
92 err.message
93 )
94 await new Promise((resolve) => setTimeout(resolve, delay * 1000))
95 }
96 }
97 }
98
99 throw new Error(
100 `Failed to ${operationName} after ${maxRetries} retries: ${lastError?.message}`
101 )
102}
103
104const testFilters = {
105 development: new RegExp('^(test/(development|e2e))'),

Callers 2

getTestTimingsFunction · 0.85
mainFunction · 0.85

Calls 2

setTimeoutFunction · 0.50
logMethod · 0.45

Tested by

no test coverage detected