Generic wrapper for retry
I'm a nodejs user, I met a lot of network error during npm
install
.
I hope a generic wrapper for retry.
nuget restore
has
nuge-restore.cmd. nuget#restore-with-retries
But this is only for nuget restore
.
I copied and pasted windows_retry.cmd and Execute-With-Retry.ps1. I use this.
I'm not familiar with cmd and powershell yet, so I hope appveyor provides a retry command. What do you think about a generic wrapper for retry?
Travis-ci has travis_retry
command.
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Chris on 09 Aug, 2016 03:14 PM
+1, would also like this.
I found this example code, am thinking of adding it to my appveyor:
https://blogs.endjin.com/2014/07/how-to-retry-commands-in-powershell/
But I don't completely understand it :-/
function Retry-Command
{
param (
[Parameter(Mandatory=$true)][string]$command,
[Parameter(Mandatory=$true)][hashtable]$args,
[Parameter(Mandatory=$false)][int]$retries = 5,
[Parameter(Mandatory=$false)][int]$secondsDelay = 2
)
# Setting ErrorAction to Stop is important. This ensures any errors that occur in the command are
# treated as terminating errors, and will be caught by the catch block.
$args.ErrorAction = "Stop"
$retrycount = 0
$completed = $false
while (-not $completed) {
try {
& $command @args
Write-Verbose ("Command [{0}] succeeded." -f $command)
$completed = $true
} catch {
if ($retrycount -ge $retries) {
Write-Verbose ("Command [{0}] failed the maximum number of {1} times." -f $command, $retrycount)
throw
} else {
Write-Verbose ("Command [{0}] failed. Retrying in {1} seconds." -f $command, $secondsDelay)
Start-Sleep $secondsDelay
$retrycount++
}
}
}
}
2 Posted by Ilya Finkelshte... on 09 Aug, 2016 04:12 PM
Hi Chris,
We actually already have appveyor-retry command. Please give it a try.
Please note that to call npm, now you need to use the following syntax:
appveyor-retry call npm install
We understand that it is not obvious, and fix is on its way, in a few days you will be able to use just:
appveyor-retry npm install
Thank you,
Ilya.
3 Posted by Sanemat on 20 Aug, 2016 12:53 AM
Hi Ilya,
I have a question.
I try to do below, but this does not work fine.
This brings error:
https://ci.appveyor.com/project/sanemat/generator-nm5/build/1.0.221...
Do you have any suggestions?
4 Posted by Ilya Finkelshte... on 20 Aug, 2016 10:25 PM
Please use
- cmd: appveyor-retry powershell Install-Product node $env:nodejs_version
This is because appveyor-retry is cmd batch, which expects some exe to be called, not PowerShell function (which install-product is). Sorry for confusion.
--ilya.
Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 02:08 AM.