Created
July 21, 2016 09:27
-
-
Save lazytesting/0b35a7a8bed4e3668330f581f30c2c64 to your computer and use it in GitHub Desktop.
ping site until it is alive (usefull to warm up your site after a deploy)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string]$url = "", | |
[int]$maxRetries = 5 | |
) | |
$SecondsDelay = 10 | |
$retrycount = 0 | |
$completed = $false | |
while (-not $completed) { | |
try { | |
Write-Host ("Checking if site is reachable..") | |
$result = Invoke-WebRequest -Uri $Uri -TimeoutSec 10 | |
$completed = $TRUE | |
Write-Host ("Site reachable! (" + $Uri + ")") | |
} catch { | |
if ($retrycount -ge $maxRetries) { | |
$completed = $TRUE | |
throw ("Site is not reachable, failed the maximum number of {1} times." -f $command, $retrycount) | |
} else { | |
Write-Host ("Site doesn't seem to be reachable... Retrying in {1} seconds." -f $command, $secondsDelay) | |
Start-Sleep $SecondsDelay | |
$retrycount++ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment