Add retries to restore-cache.mjs
This commit is contained in:
+23
-10
@@ -17,16 +17,29 @@ console.log(`Restoring cache with key: ${key}`)
|
|||||||
console.log(`Paths: ${paths.join(', ')}`)
|
console.log(`Paths: ${paths.join(', ')}`)
|
||||||
console.log(`Using Azure SDK: ${options.useAzureSdk}`)
|
console.log(`Using Azure SDK: ${options.useAzureSdk}`)
|
||||||
|
|
||||||
try {
|
const maxRetries = 3
|
||||||
const restoredKey = await cache.restoreCache(paths, key, [], options)
|
const retryDelayMs = 5000
|
||||||
|
|
||||||
if (restoredKey) {
|
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
||||||
console.log(`Cache restored with key: ${restoredKey}`)
|
try {
|
||||||
} else {
|
console.log(`Attempt ${attempt} of ${maxRetries}`)
|
||||||
console.error('Cache not found')
|
const restoredKey = await cache.restoreCache(paths, key, [], options)
|
||||||
process.exit(1)
|
|
||||||
|
if (restoredKey) {
|
||||||
|
console.log(`Cache restored with key: ${restoredKey}`)
|
||||||
|
process.exit(0)
|
||||||
|
} else {
|
||||||
|
console.log('Cache not found on this attempt')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error on attempt ${attempt}:`, error.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attempt < maxRetries) {
|
||||||
|
console.log(`Waiting ${retryDelayMs / 1000}s before retry...`)
|
||||||
|
await new Promise(resolve => setTimeout(resolve, retryDelayMs))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
console.error('Error restoring cache:', error)
|
|
||||||
process.exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.error(`Failed to restore cache after ${maxRetries} attempts`)
|
||||||
|
process.exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user