feat: retry git push
This commit is contained in:
parent
29708c335a
commit
b8d27464d1
4 changed files with 3011 additions and 2 deletions
36
src/git-push-retry.ts
Normal file
36
src/git-push-retry.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
import Bottleneck from 'bottleneck'
|
||||
import * as core from '@actions/core'
|
||||
import {GitCommandManager} from './git-command-manager'
|
||||
|
||||
const retryableErrors = [
|
||||
'You have triggered an abuse detection mechanism and have been temporarily blocked from content creation. Please retry your request again later.'
|
||||
]
|
||||
const maxRetries = 3
|
||||
const waitMilliseconds = 60000
|
||||
|
||||
const limiter = new Bottleneck()
|
||||
|
||||
limiter.on('failed', async (error, jobInfo) => {
|
||||
const id = jobInfo.options.id
|
||||
core.info(`Job '${id}' failed: ${error}`)
|
||||
|
||||
if (error.message in retryableErrors && jobInfo.retryCount < maxRetries) {
|
||||
core.info(`Retrying job '${id}' in ${waitMilliseconds}ms`)
|
||||
return waitMilliseconds + randomFromInterval(0, 10000)
|
||||
}
|
||||
})
|
||||
|
||||
limiter.on('retry', (error, jobInfo) =>
|
||||
core.info(`Now retrying job '${jobInfo.options.id}'`)
|
||||
)
|
||||
|
||||
function randomFromInterval(min, max) {
|
||||
return Math.floor(Math.random() * (max - min + 1) + min)
|
||||
}
|
||||
|
||||
export async function pushWithRetry(
|
||||
git: GitCommandManager,
|
||||
options: string[]
|
||||
): Promise<void> {
|
||||
await limiter.schedule({id: 'git push'}, () => git.push(options))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue