How to check Continuous Webjobs Stop and Start properly done or not through PowerShell?

落花浮王杯 提交于 2020-01-06 06:50:24

问题


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 ?


回答1:


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

 }

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

 }


来源:https://stackoverflow.com/questions/47788684/how-to-check-continuous-webjobs-stop-and-start-properly-done-or-not-through-powe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!