I have a HTTP triggered function inside my function app - it is invoked by the webhook connector in Azure Logic Apps. The way webhooks work in Logic Apps is they need the initial response like "status:200"
which puts the Logic App to sleep and then when the "work" is done the callbackURL
is invoked and then the Logic App resumes work. My problem is responding with that initial response from my function app.
If you don't respond to the webhook with a status:2** within 2 minutes then the webhook "retries" which starts a new instance of the function app and that is obviously problematic.
So my code looks something like this
try
{
await function1() // this function runs more than 2 minutes
}
catch(err)
{
context.log(err)
}
finally
{
await function2() // this function returns to LogicApp via callbackurl
}
I have tried adding context.res = { status:200}
in the try block and have tried creating an individual function that has context.res = {status:200}
inside, however none of those work.
If my function runs under 2 minutes then obviously the webhook doesn't retry, however when it does take over 2 minutes it fails.
I tried to build based on the "Webhook" design from this article
Calling Long Running Functions Azure
These are the combinations I have tried:
try {
context.bindings.res = {status:202}
await function1()
}
try {
context.res = {status:202}
await function1()
}
try {
await initialResponse(context)// function that has context.res={status:202} inside
function1()
}
try {
context.res = {status:202}
context.done()
await function1()
} // I added @UncleDave 's suggestion as well
try {
await initialResponse(context)
function1()
}
async function initialResponse(context)
{
context.res = {status:202}
context.done()
} // this attempt also just ended the function