Add small delay
This commit is contained in:
parent
3c0903ad5b
commit
d7374da072
3 changed files with 55 additions and 39 deletions
42
index.js
42
index.js
|
|
@ -1,4 +1,5 @@
|
|||
const fs = require('fs')
|
||||
const { setTimeout } = require('timers/promises')
|
||||
const core = require('@actions/core')
|
||||
const cache = require('@actions/cache')
|
||||
const glob = require('@actions/glob')
|
||||
|
|
@ -70,32 +71,35 @@ async function restoreCache (cacheConfig) {
|
|||
return
|
||||
}
|
||||
|
||||
core.startGroup(`Restore cache for ${cacheConfig.name}`)
|
||||
const delay = Math.random() * 1000 // timeout <= 1 sec to reduce 429 errors
|
||||
await setTimeout(delay, async function () {
|
||||
core.startGroup(`Restore cache for ${cacheConfig.name}`)
|
||||
|
||||
const hash = await glob.hashFiles(cacheConfig.files.join('\n'))
|
||||
const name = cacheConfig.name
|
||||
const paths = cacheConfig.paths
|
||||
const restoreKey = `${config.baseCacheKey}-${name}-`
|
||||
const key = `${restoreKey}${hash}`
|
||||
const hash = await glob.hashFiles(cacheConfig.files.join('\n'))
|
||||
const name = cacheConfig.name
|
||||
const paths = cacheConfig.paths
|
||||
const restoreKey = `${config.baseCacheKey}-${name}-`
|
||||
const key = `${restoreKey}${hash}`
|
||||
|
||||
console.log(`Attempting to restore ${name} cache from ${key}`)
|
||||
console.log(`Attempting to restore ${name} cache from ${key}`)
|
||||
|
||||
const restoredKey = await cache.restoreCache(
|
||||
paths, key, [restoreKey],
|
||||
{ segmentTimeoutInMs: 300000 } // 5 minutes
|
||||
)
|
||||
const restoredKey = await cache.restoreCache(
|
||||
paths, key, [restoreKey],
|
||||
{ segmentTimeoutInMs: 300000 } // 5 minutes
|
||||
)
|
||||
|
||||
if (restoredKey) {
|
||||
console.log(`Successfully restored cache from ${restoredKey}`)
|
||||
if (restoredKey) {
|
||||
console.log(`Successfully restored cache from ${restoredKey}`)
|
||||
|
||||
if (restoredKey === key) {
|
||||
core.saveState(`${name}-cache-hit`, 'true')
|
||||
if (restoredKey === key) {
|
||||
core.saveState(`${name}-cache-hit`, 'true')
|
||||
}
|
||||
} else {
|
||||
console.log(`Failed to restore ${name} cache`)
|
||||
}
|
||||
} else {
|
||||
console.log(`Failed to restore ${name} cache`)
|
||||
}
|
||||
|
||||
core.endGroup()
|
||||
core.endGroup()
|
||||
}())
|
||||
}
|
||||
|
||||
run()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue