File size: 1,498 Bytes
32c5da4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
param(
  [string]$BackendUrl = "http://127.0.0.1:8008",
  [string]$A1111Url = "http://127.0.0.1:7860",
  [int]$TimeoutSeconds = 60,
  [switch]$RequireA1111
)

$ErrorActionPreference = "Stop"

function Wait-Endpoint {
  param(
    [Parameter(Mandatory = $true)][string]$Url,
    [Parameter(Mandatory = $true)][string]$Name,
    [Parameter(Mandatory = $true)][int]$Timeout
  )

  $deadline = (Get-Date).AddSeconds($Timeout)
  do {
    try {
      $resp = Invoke-RestMethod -Uri $Url -Method Get -TimeoutSec 5
      Write-Host "OK  $Name -> $Url"
      return $resp
    }
    catch {
      Start-Sleep -Milliseconds 750
    }
  } while ((Get-Date) -lt $deadline)

  throw "$Name not reachable within ${Timeout}s: $Url"
}

$null = Wait-Endpoint -Url "$BackendUrl/health" -Name "Backend health" -Timeout $TimeoutSeconds
$null = Wait-Endpoint -Url "$BackendUrl/ready" -Name "Backend readiness" -Timeout $TimeoutSeconds

$models = Wait-Endpoint -Url "$BackendUrl/models" -Name "Backend models" -Timeout $TimeoutSeconds
$a1111Model = $models | Where-Object { $_.id -eq "a1111" } | Select-Object -First 1
if ($null -eq $a1111Model) {
  throw "Model 'a1111' is not registered in backend /models response"
}

if ($RequireA1111.IsPresent) {
  $null = Wait-Endpoint -Url "$A1111Url/sdapi/v1/sd-models" -Name "A1111 API" -Timeout $TimeoutSeconds
  if (-not $a1111Model.available) {
    throw "A1111 API reachable but backend still reports a1111.available=false"
  }
}

Write-Host "Stack readiness check passed."