feature(wakeup): run multiple connectivity checks up to timeout

This commit is contained in:
Asif Bacchus 2021-09-06 15:38:36 -06:00
parent 0119923ed7
commit 5332818990

View File

@ -131,6 +131,7 @@ $targetComputers | ForEach-Object {
else else
{ {
Write-Host -ForegroundColor Red "[ERROR]" Write-Host -ForegroundColor Red "[ERROR]"
# queue for removal from computers on which to run a connectivity check
$removeFromTargetComputers.Add($name) $removeFromTargetComputers.Add($name)
} }
} }
@ -152,7 +153,7 @@ elseif ($targetComputers.Count -eq 0)
exitError "No wake-up packets sent successfully" -exitCode 5 exitError "No wake-up packets sent successfully" -exitCode 5
} }
# wait for initialWaitTime seconds to let computer(s) wake up # wait for initial delay seconds to let computer(s) wake up
for ($i = $ConnectivityCheckDelay; $i -gt 0; $i--) { for ($i = $ConnectivityCheckDelay; $i -gt 0; $i--) {
Write-Progress -Activity "Waiting for computer(s) to wake-up..." -SecondsRemaining $i Write-Progress -Activity "Waiting for computer(s) to wake-up..." -SecondsRemaining $i
Start-Sleep 1 Start-Sleep 1
@ -162,8 +163,10 @@ Write-Progress -Activity "Waiting for computer(s) to wake-up..." -Completed
# iterate computers and test connectivity # iterate computers and test connectivity
# TODO: run multiple connectivity tests as needed, spaced evenly apart up to max timeout THEN fail # TODO: run multiple connectivity tests as needed, spaced evenly apart up to max timeout THEN fail
# TODO: run connectivity test as background job # TODO: run connectivity test as background job
$connCheckTotalTime = 0
$removeFromTargetComputers.Clear()
while ($connCheckTotalTime -le $ConnectivityCheckTimeout -and $targetComputers.Count -gt 0)
{
$targetComputers | ForEach-Object { $targetComputers | ForEach-Object {
$name = $_.name $name = $_.name
$friendlyName = $_.friendlyName $friendlyName = $_.friendlyName
@ -189,6 +192,26 @@ $targetComputers | ForEach-Object {
else else
{ {
Write-Host -ForegroundColor Green "[OK]" Write-Host -ForegroundColor Green "[OK]"
# queue for removal from computers to check next round
$removeFromTargetComputers.Add($name)
}
}
# remove computers from targetComputers if connectivity check already successful
$removeFromTargetComputers | ForEach-Object {
$removeName = $_
$targetComputers.Remove(($targetComputers | Where-Object { $_.name -eq $removeName })) | Out-Null
}
# sleep until next test interval and increase time counter
if ($targetComputers.Count -gt 0)
{
for ($i = $ConnectivityCheckInterval; $i -gt 0; $i--) {
Write-Progress -Activity "Waiting for next connectivity check..." -SecondsRemaining $i
Start-Sleep 1
}
Write-Progress -Activity "Waiting for next connectivity check..." -Completed
$connCheckTotalTime += $ConnectivityCheckInterval
} }
} }