How to Handle Long-Running Azure Function Callbacks in a Logic App Without Timing Out?

bob 0 Reputation points
2024-04-22T12:38:15.5166667+00:00

am a bit lost on this and hope someone can point me in the right direction.

We have an Azure Logic App workflow that triggers several functions, some of which take 30 minutes to 5 hours to run. However, after 10 to 15 minutes, it will timeout because the functions are running too long and throw the following error message:

Http request failed: the server did not respond within the timeout limit. Please see logic app limits at https://aka.ms/logic-apps-limits-and-config#http-limits.

Now, as a workaround, I am trying to use a webhook to invoke the Azure Function via an HTTP request. Instead of continuously polling, it should remain idle until my function is done running and triggers a call to the callback URL.

What I did was create an HTTP webhook that triggers my Azure Function. This works since the function is being triggered, and when executing Write-Host, both tenantId and callbackUri are shown in the output.

Webhook

The tenantId and callbackUru are shown in the output:

Output

I tried following this link, but unfortunately, it's behind a Medium paywall: https://blog.devgenius.io/invoking-long-running-functions-from-logic-apps-powershell-edition-6caa96b95981

But after retrieving the callbackUri within the Function app, the next step according to the blog is to:

$response = $client.GetAsync($callbackUri)

However, this kept giving me the following error message:

ERROR: You cannot call a method on a null-valued expression.

So I tried somethings like:

Add-Type -AssemblyName System.Net.Http
$httpClient = New-Object System.Net.Http.HttpClient
$response = $httpClient.GetAsync($callbackUri)

When printing the response variable I get the following:

INFORMATION: System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox1[System.Net.Http.HttpResponseMessage,System.Net.Http.HttpClient+<<SendAsync>g__Core|83_0>d]

But since the Logic App is still timing out after 10-15 minutes, I guess it's still not working correctly.

At the end of my code, I have the following, which will send a response back to the callback URL. However, it never gets there since the Azure Logic App has already timed out before it reaches this statement.

Invoke-WebRequest -Method Post -Uri $callbackUri -ContentType 'application/json'

After a few days of struggling, I'm a bit lost on what else to try, so I was wondering if someone could point me in the right direction or if there is a better alternative for doing this.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,296 questions
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,855 questions
{count} votes