停止触发的Web作业的最佳方法是什么 [英] What is the best way to stop triggered web jobs

查看:77
本文介绍了停止触发的Web作业的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从类似的团队那里得到了要求,目前他们通过设置计划以特定的间隔运行触发的作业.他们已经设置了计划,因此按照计划的时间这些触发的作业将运行,但是在部署时,我们必须确保触发的作业不运行,因为它不会接受部署jar的天蓝色.所以我要运行webjobs连续的作业停止并且触发的作业不应该运行.它应该检查触发的作业当时的运行情况如果它正在运行,即使您停止连续作业,我们也无法部署jar.请帮助我.如何完成上述任务?是否需要添加任何脚本来检查触发的作业是否运行,以及是否运行如何部署jar.

I got requirement from team like ,currently they are running the triggered jobs at particular intervals by setting up the schedule.They have setup schedule ,so as per the scheduled time those triggered jobs will run but at the time of deploy we must make sure the triggered jobs shouldn't run as it will not accept the deploy jar's into azure.So I want to run webjobs continuous jobs stop and as well as triggered jobs shouldn't run.It should check the triggered job running at the time of deploy if its running we can't deploy jar's even though if u stop continuous jobs.Please help me.How to accomplish the above task? whether we need to add any script to check triggered jobs running or not if it runs how to deploy jar's.

和其他要求类似,当前我们正在传递像

And other requirement is like,currently we are passing the parameters like

-webjobs @(@ {"name" ="abc";"typeName" ='continuous'},@ {"name" ="def";"ty‌peName" ='continuous'‌})-网站kgh -rg ghi ....

-webjobs @(@{"name"="abc";"typeName"='continuous'},@{"name"="def";"ty‌​peName"='continuous'‌​}) -website kgh -rg ghi....

但是团队希望这些参数可以在一个单独的文件中传递.因此,当他们添加新的Web作业时,他们可以在文件本身中添加.如果我将参数脚本放在一个单独的文件中并传递给webjobs脚本.

But team want these parameters will be passed in a separate file.So that when they add new web job they can add in a file itself.how can I call if I put the parameter script in a separate file and pass to the webjobs script.

任何部署webjobs的工作后,我都应验证webjobs是否正确启动.因此,我需要在脚本中实现这三个要求.请与我分享完整满足以上要求的脚本.

Any post deploy of webjobs I should validate whether the webjobs are started properly or not.So these 3 requirements I need to implement in the script.Kindly share me the script full filling the above requirement.

推荐答案

您可以通过

You can get the processes of current web app through Process kudu API, then check whether there is the process related to the WebJob (process name), if so, kill that process.

例如:

param(
[string]$webJobName,
[string]$userName,
[string]$password,
[string]$webAppName
)
$kuduApiAuthorisationToken="Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $userName, $password)))
$kuduApiUrl="https://$webAppName.scm.azurewebsites.net/api/processes/"
$processes=Invoke-RestMethod -Uri $kuduApiUrl -Headers @{"Authorization"=$kuduApiAuthorisationToken;"If-Match"="*"} -Method GET
foreach($p in $processes){
    if($p.name -eq $webJobName){
    $killAPI="https://$webAppName.scm.azurewebsites.net/api/processes/$($p.id)"
    Invoke-RestMethod -Uri $killAPI -Headers @{"Authorization"=$kuduApiAuthorisationToken;"If-Match"="*"} -Method DELETE
    }
}

参数:-webJobName "XX" -userName "XX" -password "XX" -webAppName "XX"

注意:如果用户名中有$,例如$test,则可以指定用户名,例如-userName`$ test"

Note: If there is $ in the username, such as $test, you can specify the username like -userName "`$test"

您可以手动或以编程方式从发布配置文件中获取用户名和密码:(在您的线程中回答:

You can get the username and password from publish profile manually or programmatically: (Answered in your thread: Could any one help me how to stop and start azure webjobs through vsts)

关于将参数放入文件中

parameter.json

parameter.json

[
  {
    "filepath": "data.csv",
    "Cols": "Col1,Col2,Col3"
  },
  {
    "filepath": "data2.csv",
    "Cols": "Col1,Col6,Col7,Col8"
  }
]

代码:

[object[]]$fileObj=Get-Content "parameter.json"|ConvertFrom-Json
foreach($fo in $fileObj){

}

更新:

Parameter.json:

Parameter.json:

{
    "userName": "user1",
    "password": "password1",
    "webAppName": "webapp1",
    "resourceGroup": "resourceGroup1",
    "webJobs": [   
      {
        "name": "abc",
        "typeName": "continuous"
      },
      {
        "name": "def",
        "typeName": "continuou‌"
      }
    ]
  }

脚本:

 [object]$paramObj=Get-Content "PowerShellModuleProject1\parameter2.json"|ConvertFrom-Json 
    $userName =$paramObj.userName
    $password =$paramObj.password
    $webAppName =$paramObj.webAppName
    $resourceGroup=$paramObj.resourceGroup
    [object[]]$webJobs=$paramObj.webJobs
    foreach($wj in $webjobs){
     if($wj.typeName -eq "continuous")
     {
Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroup -ResourceType Microsoft.Web/sites/ContinuousWebJobs -ResourceName "$webAppName/$($wj.name)" -Action start -ApiVersion 2015-08-01 -Force
      Write-Host "continuous"
     Write-Host $wj.name
     }
     else{
     Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroup -ResourceType Microsoft.Web/sites/TriggeredWebJobs -ResourceName "$webAppName/$($wj.name)" -Action run -ApiVersion 2015-08-01 -force
     Write-Host "triggered"
     Write-Host $wj.name
     }
     }

这篇关于停止触发的Web作业的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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