Skip to content

Instantly share code, notes, and snippets.

@lazytesting
Created July 21, 2016 09:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazytesting/0b35a7a8bed4e3668330f581f30c2c64 to your computer and use it in GitHub Desktop.
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)
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