在交换暂存/生产槽(交换VIP)之前等待新部署完全初始化?

And*_*son 1 powershell azure

我使用以下代码将我新部署的应用程序从暂存槽交换到生产槽(交换VIP):

Get-HostedService -serviceName $serviceName -subscriptionId $subcription -certificate $certificate | Get-Deployment -slot staging | Move-Deployment |Get-OperationStatus –WaitToComplete
Run Code Online (Sandbox Code Playgroud)

我认为-WaitToComplete标志会确保所有虚拟机在进行交换之前已经完全初始化,但它没有完成初始化,并且它执行交换,此时生产槽中新部署的应用程序仍在初始化并且不可用于大约5/10分钟,同时完全初始化.

在执行Swap VIP操作之前,确保应用程序完全初始化的最佳方法是什么?

Ric*_*ury 9

此PowerShell代码段将等待,直到每个实例都准备就绪(以@astaykov给出的答案为基础).

它查询暂存槽中正在运行的实例的状态,并且只有当所有实例都显示为"就绪"时才会离开循环.

$hostedService = "YOUR_SERVICE_NAME"

do {
    # query the status of the running instances
    $list = (Get-AzureRole -ServiceName $hostedService `
                           -Slot Staging `
                           -InstanceDetails).InstanceStatus 

    # total number of instances
    $total = $list.Length

    # count the number of ready instances
    $ready = ($list | Where-Object { $_ -eq "ReadyRole" }).Length

    Write-Host "$ready out of $total are ready"

    $notReady = ($ready -ne $total)
    If ($notReady) {
        Start-Sleep -s 10
    }
}
while ($notReady)
Run Code Online (Sandbox Code Playgroud)