如何通过PowerShell检查连续Webjobs停止和启动是否正确完成? [英] How to check Continuous Webjobs Stop and Start properly done or not through PowerShell?

查看:107
本文介绍了如何通过PowerShell检查连续Webjobs停止和启动是否正确完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以建议我如何完成webjobs的验证,然后停止并正确开始吗?目前,我正在通过PowerShell停止和启动webjobs,但是我需要在停止之后进行验证并开始进行是否正确的操作.请分享您的想法.由于我不断在网上和博客中搜索适当的解决方案,因此无法提供任何解决方案确切的解决方案.我正在使用VSTS PowerShell任务通过VSTS运行PowerShell脚本.否则,请更新任何其他方法来从VSTS验证Web作业吗?

Can anyone please suggest me how to accomplish the validation of webjobs stop and start properly happened or not ? Currently,I am stopping and starting the webjobs through PowerShell but I need to validate after the stop and start whether properly done or not.Please share your thoughts on this.As I am continuously searching online and blogs for the proper solution no once can provide the exact solution to this.I am running the PowerShell scripts through VSTS using VSTS PowerShell Task.Or else please update any other way to validate webjobs from VSTS ?

推荐答案

它需要花费几秒钟的时间来停止webjob,因此您可以在几秒钟后检查状态.例如:

It tasks a few seconds to stop the webjob, so you can check the status after few seconds. For example:

[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."
}

 }

这篇关于如何通过PowerShell检查连续Webjobs停止和启动是否正确完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆