Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.