问题描述
我想通过在Power Shell中编写代码的Runbook处理多维数据集,我想从ADF的webhook活动中调用此Runbook,但是此活动一直运行到超时,但是无法完成,但是其处理通过触发运行手册成功多维数据集。为了使它在ADF中成功还是失败,我是否还必须编写一些代码。还是我的配置中缺少其他内容。
解决方法
如果您希望ADF等待运行手册完成,那么Webhook活动(就像您正在做的那样)是正确的。但是您的Runbook需要使用$webhookData parameter in the Azure Automation webhook documentation接受callbackUri参数。然后,Runbook需要通过Web调用ADF回调API来使其完成。
另一方面,如果您不希望ADF等待或不知道Runbook是否失败,则使用Web活动而不是Webhook活动。
如果继续使用ADF Webhook,则需要更改Azure Automation Runbook,使其包括以下参数并进行解析:
param(
[object] $WebhookData
)
$ErrorActionPreference = "Stop";
try
{
#parse the webhook parameters
if (-Not $WebhookData.RequestBody)
{
#we're testing in the test pane
$WebhookData = ConvertFrom-Json -InputObject $WebhookData
}
$WebhookBody = ConvertFrom-Json -InputObject $WebhookData.RequestBody
[string] $callbackUri = $WebhookBody.callbackUri
#complete your typical runbook work here...
if ($callbackUri)
{
$null = Invoke-WebRequest -Method Post -Uri $callbackUri -ContentType "application/json" -Body '{"StatusCode": "200"}' -UseBasicParsing
}
}
catch
{
if ($callbackUri)
{
$null = Invoke-WebRequest -Method Post -Uri $callbackUri -ContentType "application/json" -Body '{"StatusCode": "500","Error": {"ErrorCode":100,"Message","$_"}}' -UseBasicParsing
}
"Failed: $_"
throw $_
}
那应该可以解决ADF认为Runbook永远运行的问题。