Microsoft Azure Logic Apps: using the do-until construct to implement a retry policy for a step

In this post we still talk about Microsoft Azure Logic Apps , and in particular of how to implement a retry policy, on a step went into error, through the use of the do-until construct.
We take as an example the Logic App we had created in the previous post, where we analyzed the bug on the SFTP connector and pointed out his resolution by Microsoft team.
Azure Logic App correct execution

In this logic app there is an action that is supposed to get a file via SFTP and that could go into error for example because the file in question is not present (but it might be later) or due to a temporary network problem.
The following image shows an example of this Logic App run failed due to an error on the get SFTP step:
Azure Logic App Failed Step

By clicking “Run details” we can obtain further information. In fact it opens a window with a list of the steps, their execution status, duration, and so on..
In this case we can see once again that the get SFTP step failed.
Azure Logic App run details
Clicking on the line of the step at issue and then, in the new window that opens on the right, on “OUTPUTS LINK” we can find information about the action failure cause.
In this case we see that it was a general problem with the connection to the SFTP server, surely temporary because further executions of the same Logic App, with the same configuration and run practically in parallel, have been successful.
Azure Logic App  Output log failed step

Here are the details of the error message we get:

"body": {
	"status": 404,
	"message": "Unable to connect to the remote server 'xxxxxxxx'.",

Being due to the temporary unavailability of the server, this is the typical error that can be resolved with subsequent attempts after a certain interval of time. So, what we need to do to solve the problem is to implement a retry policy for this step of the Azure App Logic.
To do this we can use the Do-Until construct that the Logic App editor provides us.

The tasks to perform are basically the following:

  • Wrap the step in question within a Do-Until construct
  • Set the number of attempts and the time interval within which to execute them
  • Define as exit condition of the loop the success of the step

So, first of all we add to the Logic App a Do-Until construct
Azure Logic App new Do Until construct
and then we put inside it the step to get the file via SFTP
Azure Logic App Do Until loop
By clicking on “Change limits” we expand the configuration section in which we can define:

  • Count: the number of repeats of the Do-Until loop that we want to perform. In our case, therefore, the maximum number of retries for the execution of the step.
  • Timeout: the maximum time interval within which to perform the number of attempts defined with “Count”

The latter value is defined by using the ISO 8601 standard, which regulates interchange formats for date and time values. In summary, to express a duration, is necessary to define a string formed from a Period (P) and a Time (T).

By default, it is set to PTM15 which means: 15 minutes

  • P: defines the Period part (that in this case is empty, because there aren’t any year, month or day)
  • T: defines the Time part
  • M15: indicates a 15 Minutes duration

Azure Logic App Do Until number and interval for retries

That said, we only need to define the exit condition for the Do-Until loop that, as mentioned, should be tied to the success of the step within the construct: if the execution is successful we must exit the loop because retry attempts are not required anymore.

In order to define this condition we move to the advanced mode for conditions configuration by clicking on “Edit in advanced mode”, and insert the following string:

@equals(actions('Get file content using path').status, 'Succeeded')

The following image shows the insertion of this configuration for the loop condition:

Azure Logic App condition on step status

In this way we are saying not to re-enter the loop if the execution status of the “Get content using file path” action, that is, our get SFTP step, is “Succeded“. If instead the step, when an error like the one in the above example occours, should end up with a “ Failed ” status, “Count” attempts would be performed in the time range defined as “Timeout”.

We have therefore implemented a retry policy on a sensitive step in our Azure Logic App.

See also:

2 thoughts on “Microsoft Azure Logic Apps: using the do-until construct to implement a retry policy for a step

  1. Pingback: Microsoft Azure Logic Apps: fixed the bug on the content-type of SFTP Connector | Dede Blog

  2. Would the same apply for HTTP Get requests in Microsoft Azure Logic Apps? And what would be the differences? E.G. Change limits, timeout, count.

Leave a Reply

Your email address will not be published. Required fields are marked *