任何人都可以建议我如何完成webjobs的验证停止并开始正确发生与否?目前,我通过PowerShell停止并启动webjobs,但我需要在停止后验证并开始是否正确完成。请分享您对此的想法。因为我不断在线搜索和博客的正确解决方案没有一次可以提供这是我的确切解决方案。我使用VSTS PowerShell Task.Or运行PowerShell脚本通过VSTS,否则请更新任何其他方法来验证VSTS的webjobs?
答案 0 :(得分:0)
它需要几秒钟才能停止webjob,因此您可以在几秒钟后检查状态。例如:
[object]$paramObj=Get-Content "d:\a\r1\a\continuous\Scripts\Webjobs_Parameters.json" |ConvertFrom-Json
$userName =$paramObj.userName
$password =$paramObj.password
$webAppName =$paramObj.webAppName
$resourceGroup=$paramObj.resourceGroup
[object[]]$webJobs=$paramObj.webJobs
$Apiversion="2016-08-01"
$webJobArr=New-Object System.Collections.ArrayList
foreach($wj in $webjobs)
{
$webJobArr.Add($wj.name)
if($wj.typeName -eq "continuous")
{
Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroup -ResourceType Microsoft.Web/sites/ContinuousWebJobs -ResourceName "$webAppName/$($wj.name)" -Action stop -ApiVersion $Apiversion -Force
Write-Host "continuous"
Write-Host "$wj.name is Stopping"
}
}
$tryCount=4
$i = 1
while($i -lt $tryCount){
$errorsJobs=New-Object System.Collections.ArrayList
Start-Sleep -s 5
Write-Host "starting $i try......."
$i +=1
$continuejobs=Get-AzureRmResource -ResourceGroupName $resourceGroup -ResourceName $webAppName -ResourceType Microsoft.web/sites/ContinuousWebJobs -ApiVersion $Apiversion
foreach($webJob in $continuejobs)
{
if($webJobArr -contains $webJob.Properties.name){
if($webJob.Properties.status -ne "Stopped"){
$errorsJobs.Add($webJob.Properties.name)
}
}
}
if($errorsJobs.Count -gt 0){
$result=$errorsJobs -join ";"
Write-Host "Some jobs are not stopped: $result. Try to check again"
}
else{
Write-Host "All jobs are stopped."
break
}
if(($i -eq $tryCount) -and ($errorsJobs.Count -gt 0)){
Write-Error "Some jobs are not stopped: $result."
}
}
更新1:
param(
[string]$currentEnv
)
[object]$paramObj=Get-Content "d:\a\r1\a\DSPPortalJobs\WebJobs_scripts\WebJob_list.json" |ConvertFrom-Json
$userName =$paramObj.$currentEnv.userName
$password =$paramObj.$currentEnv.password
$webAppName =$paramObj.$currentEnv.webAppName
$resourceGroup=$paramObj.$currentEnv.resourceGroup
[object[]]$webJobs=$paramObj.$currentEnv.webJobs
$Apiversion="2016-08-01"
$webJobArr=New-Object System.Collections.ArrayList
foreach($wj in $webjobs)
{
$webJobArr.Add($wj.name)
}
$tryCount=4
$i = 1
while($i -lt $tryCount){
$errorsJobs=New-Object System.Collections.ArrayList
Start-Sleep -s 5
Write-Host "starting $i try......."
$i +=1
$continuejobs=Get-AzureRmResource -ResourceGroupName $resourceGroup -ResourceName $webAppName -ResourceType Microsoft.web/sites/ContinuousWebJobs -ApiVersion $Apiversion
foreach($webJob in $continuejobs)
{
if($webJobArr -contains $webJob.Properties.name){
if($webJob.Properties.status -ne "Running"){
$errorsJobs.Add($webJob.Properties.name)
}
}
}
if($errorsJobs.Count -gt 0){
$result=$errorsJobs -join ";"
Write-Host "Some jobs are not Running: $result. Try to check again"
}
else{
Write-Host "All jobs are Running."
break
}
if(($i -eq $tryCount) -and ($errorsJobs.Count -gt 0)){
Write-Error "Some jobs are not Running: $result."
}
}