Azure 数据工厂 Webhook Activity 1 分钟后超时
Azure Data Factory's Web Hook Activity times out after 1 minute
我有一个带有 Web Hook Activity 的 Azure Data Factory V2,用于调用带有 HTTP 触发器的 Azure 函数,代码如下。
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Interact with query parameters or the body of the request.
$callBackUri = $Request.Body.callBackUri
Write-Output "CallBack url is : $callBackUri"
# Need to return Http 202 Accepted here
# This is the issue, it does not actually return from this point at the moment
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::Accepted
Body = $body
}) -Clobber
# some long running processing
$seconds = 60
Write-Output "Returned http 202. Sleeping for $seconds seconds.."
Start-Sleep -Second $seconds
Write-Output "Sleep complete."
# Invoke the callback
Invoke-WebRequest -Uri $callBackUri -Method POST -ContentType 'application/json' -Body "This is a callback"
函数应该接收 HTTP 请求,return HTTP 202 Accepted 立即响应,然后继续处理。处理完成后,该函数需要在 callBackUri 上调用 POST 以向 Web Hook Activity 指示处理已完成。
但是,该函数不会 return 一个 202,而是完成它的长 运行 过程,然后 return 一个 203。我知道最初的输出绑定已设置并且它仅在整个脚本执行后 returned。
有办法解决这个问题吗?我只是想实现这个:https://mrpaulandrew.com/2019/06/18/azure-data-factory-web-hook-vs-web-activity/
我试过了,Start-Job,Start-ThreadJob, Invoke-Command 的所有变体都试图在不等待的情况下调用异步 REST 请求(fire忘了)从功能应用程序但失败了。
这对我来说似乎是合乎逻辑的,因为如果允许这样做,人们会简单地 运行 后台线程上的所有内容而不等待它们完成,这将破坏 Function app - serverless 的目的。
我已经解决的是使用相同的 Invoke-RestRequest 并尝试 1 秒超时catch 来抑制超时异常。这导致请求立即超时,函数应用程序将完成。
代码如下所示:
$Body = @{
callbackUri = $Request.Body.callBackUri;
} | ConvertTo-Json
try{
# This API will be responsible for issuing the call back after it has finished the long running process
$output = Invoke-RestMethod -Method Post -Body $Body -Uri $funcapp2Url -ContentType 'application/json' -TimeoutSec 1
}
catch {
Write-Output $_
}
# Return HTTP 202 immediately
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::Accepted
Body = "Wait for callback"
}) -Clobber
我有一个带有 Web Hook Activity 的 Azure Data Factory V2,用于调用带有 HTTP 触发器的 Azure 函数,代码如下。
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Interact with query parameters or the body of the request.
$callBackUri = $Request.Body.callBackUri
Write-Output "CallBack url is : $callBackUri"
# Need to return Http 202 Accepted here
# This is the issue, it does not actually return from this point at the moment
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::Accepted
Body = $body
}) -Clobber
# some long running processing
$seconds = 60
Write-Output "Returned http 202. Sleeping for $seconds seconds.."
Start-Sleep -Second $seconds
Write-Output "Sleep complete."
# Invoke the callback
Invoke-WebRequest -Uri $callBackUri -Method POST -ContentType 'application/json' -Body "This is a callback"
函数应该接收 HTTP 请求,return HTTP 202 Accepted 立即响应,然后继续处理。处理完成后,该函数需要在 callBackUri 上调用 POST 以向 Web Hook Activity 指示处理已完成。
但是,该函数不会 return 一个 202,而是完成它的长 运行 过程,然后 return 一个 203。我知道最初的输出绑定已设置并且它仅在整个脚本执行后 returned。
有办法解决这个问题吗?我只是想实现这个:https://mrpaulandrew.com/2019/06/18/azure-data-factory-web-hook-vs-web-activity/
我试过了,Start-Job,Start-ThreadJob, Invoke-Command 的所有变体都试图在不等待的情况下调用异步 REST 请求(fire忘了)从功能应用程序但失败了。
这对我来说似乎是合乎逻辑的,因为如果允许这样做,人们会简单地 运行 后台线程上的所有内容而不等待它们完成,这将破坏 Function app - serverless 的目的。
我已经解决的是使用相同的 Invoke-RestRequest 并尝试 1 秒超时catch 来抑制超时异常。这导致请求立即超时,函数应用程序将完成。
代码如下所示:
$Body = @{
callbackUri = $Request.Body.callBackUri;
} | ConvertTo-Json
try{
# This API will be responsible for issuing the call back after it has finished the long running process
$output = Invoke-RestMethod -Method Post -Body $Body -Uri $funcapp2Url -ContentType 'application/json' -TimeoutSec 1
}
catch {
Write-Output $_
}
# Return HTTP 202 immediately
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::Accepted
Body = "Wait for callback"
}) -Clobber