fix(startup): defer alarm pull 60s; health probe accepts only HTTP 200

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-06-04 21:32:07 +08:00
parent f562f50953
commit 65e0713e94
3 changed files with 30 additions and 3 deletions

View file

@ -95,10 +95,17 @@ function Show-LogTail {
function Test-NetxApiListening {
param([string]$HostName, [int]$LocalPort, [int]$WaitSec = 45)
$deadline = (Get-Date).AddSeconds($WaitSec)
$healthUrl = "http://${HostName}:${LocalPort}/health"
while ((Get-Date) -lt $deadline) {
try {
$r = Invoke-WebRequest -Uri "http://${HostName}:${LocalPort}/health" -UseBasicParsing -TimeoutSec 2
if ($r.StatusCode -eq 200) { return $true }
# Only HTTP 200 with {"status":"ok"} counts; no redirects / other codes.
$r = Invoke-WebRequest -Uri $healthUrl -UseBasicParsing -TimeoutSec 2 -MaximumRedirection 0
if ($r.StatusCode -ne 200) {
Start-Sleep -Milliseconds 500
continue
}
$body = $r.Content | ConvertFrom-Json -ErrorAction Stop
if ($body.status -eq "ok") { return $true }
} catch {}
Start-Sleep -Milliseconds 500
}