Background
Azure Logic Apps is a cloud platform where you can create and run automated workflows with little to no code. There are two types of plans available for Logic App. A standard plan and a consumption-based plan. Consumption-based plan is a serverless model, it is a pay-as-you-go pricing model that charges based on triggers and actions that are specified in a logic app. The default timeout for consummation-based plan is 5 minutes, which we can increase up to 10 minutes. It means that for every action within a consumption-based logic app, should complete the activity within 10 minutes. However, if there is a use case where the activity may take more than 10 minutes, then the logic app will fail.
Use Case
Let us consider one use case where a logic app is processing a lot of data, and the data processing is causing a timeout issue.
Pattern
To resolve this timeout issue, we can use a logic app with an http webhook activity. This is also known as the Asynchronous Request-Reply pattern. The steps are given below:
- The client application [in our case, this is a logic app] makes a synchronous call to the API, triggering a long-running operation on the backend.
- The API responds synchronously as quickly as possible. It returns an HTTP 202 (Accepted) status code, acknowledging that the request has been received for processing. [ For this, we will use http function]
- The response holds a location reference pointing to an endpoint that the client can poll to check for the result of the long-running operation.
- The API offloads processing to another component, such as a message queue.
- For every successful call to the status endpoint, it returns HTTP 200. While the work is still pending, the status endpoint returns a resource that indicates the work is still in progress. Once the work is complete, the status endpoint can either return a resource that indicates completion or redirect to another resource URL. [ For this example, the background job will call the url once processing is complete.]
![Pattern]()
Solution
For our use case, we can use the above pattern to resolve the timeout issue. We can delegate the data processing to another process. We can set up an api that will return HTTP 202 (Accepted), and then the logic app will go to a sleep mode, a background job will process the data, and once processing is complete, the background job will call the callback url, which will reactivate the logic app.
Set up the component in Logic App
To implement the pattern described above, we need to do the following steps:
a. Add an action and choose Http Webhook as shown below
![Actions]()
![HTTP Webhook]()
We need to give the method type, i.e, HTTP POST or HTTP GET. We need to give the subscribe URI, which is nothing but the url of the http method that will return the http 202 once it receives the message. In the body, we will pass the callback url and the data. Here, the callback url is the url that the background job will call once processing is complete.
![Body]()
b. HTTP-triggered Azure function
For step 2 of the pattern implementation, we will use a http triggered azure function; this is the API that responds synchronously as quickly as possible. It returns an HTTP 202 (Accepted) status code, acknowledging that the request has been received for processing. Please refer to the sample code. Here we are posting the data in a queue.
log.LogInformation("Webhook request from Logic Apps received.");
string requestBody = new StreamReader(req.Body).ReadToEnd();
dynamic data = JsonConvert.DeserializeObject(requestBody);
string callbackUrl = data?.callbackUrl;
var blobName = data?.data;
// This will drop a message in a queue that QueueTrigger will pick up
process = new ProcessRequest { callbackUrl = callbackUrl, FileName = blobName };
return new AcceptedResult();
c. Background job
The background job will read from the queue message and then process the data. Once the data processing is complete, it will call the callback url, which will reactivate the logic app from the state where it went to sleep, and then the rest of the steps of the logic app will be executed. And there will be no timeout issue. Refer to the sample code given below.
HttpClient client = new HttpClient();
var responseHttp = await client.PostAsync(callbackUrl, null);