Answers for "pipeline task to warmup site"

0

pipeline task to warmup site

param(
    [Parameter(Mandatory)]
    [string]
    $rootUrl
)

#Make sure that website is alive
for($tryIndex=0; $tryIndex -le 10; $tryIndex++){
    try{
        $time =  Measure-Command{Invoke-WebRequest $rootUrl -UseBasicParsing -ErrorAction Stop -ErrorVariable siteIsNotAlive}
        Write-Host "Site is running"
        Write-Host "wget $rootUrl in $($time.TotalSeconds)"
        break;
    }
    catch{
        Write-Host "Sleep + repeat"
        Start-Sleep -s 1
    }
}

#url suffixes
$suffixes = @("/", "/url_1", "url_2")

$suffixes | ForEach-Object{
    $url = $rootUrl+$_;
    $time = Measure-Command{Invoke-WebRequest $url -UseBasicParsing}
    Write-Host "wget $url in $($time.TotalSeconds)"
}
Posted by: Guest on June-07-2021

Browse Popular Code Answers by Language