Back when I was a BizTalk developer I used something called sequential convoys. Two main features that had to be implemented to use that pattern was a timeout shape, and a parallel branch. The flow either received a new message or it “timed out”, executing some other logic, perhaps sending an aggregated batch to a database.
Looking at logic apps the same pattern does not match 100% but there are still very good uses for parallel actions and clever use of the delay action.
Can a Logic App timeout?
The question is quite fair: How can we get a behavior that makes the Logic App send back a timeout if a run does not complete within a given time frame? In order to illustrate this I have set up a Logic App that takes inspiration from the sequential convoy pattern:
- Receives a request
- Starts a delay (the timeout) in one branch.
- Starts a call to an external service in the other branch.
- If the service responds back before the delay (timeout) is done, HTTP 200 is sent back.
- If the service does not respond back in time, HTTP 504 (Gateway timeout) is sent back.
For demo reasons I have added another delay shape to the “call the service”-branch to make the call take too long, and to trigger the timeout.
The Logic App
If the TimeoutResponse triggers, the Logic App engine will recognize this and it will not try to send the other response. That action will be skipped. If you execute the Logic App and this happens the run will be marked as “Failed” in the run history, which then in turn points to a timeout.
The json for the Logic App can be found here.
Some caveats and perhaps better solutions
Note that in this Logic App, the HTTP call to the service will still be executed, even if TimeoutResponse will execute. That can be fixed using the Terminate action.
Lastly you also should think about why you need to implement a timeout in a Logic App. Can’t the calling client set a timeout on their end? If not, why? Can this be solved in some other way? If there is a risk of timing out, can you rebuild the messaging paths in a more async (webbhook) manor? One call from the client starts one process and another Logic App sends the result when the processing is done.
I might find scenarios when this is very useful. I have yet to find it but it is nice to know that it’s there and how it behaves.