I have an Azure Data Factory V2 with a Web Hook Activity which is used to invoke an Azure Function with HTTP trigger, code as below.
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"
The Function is supposed to receive the HTTP request, return an HTTP 202 Accepted response immediately and then continue processing. After the process is complete it the function needs to invoke a POST on the callBackUri to indicate to the Web Hook Activity that the processing is complete.
However, the function does not return a 202, instead it completes it's long running process and then returns a 203. I do understand that initially output binding is set and it is returned only after the entire script is executed.
Is there a way around this? I am simply trying to implement this: https://mrpaulandrew.com/2019/06/18/azure-data-factory-web-hook-vs-web-activity/