I have an azure logic app with an azure service bus trigger.
The message is locked for 1 minute, but if the operation doesn’t finish in 1 minute, the message is put back into the service bus queue and another run is triggered – thus I have 2 parallel running and the operation would happen twice.
How can I force the pervious execution to halt, after 1 minute or after the lock time is expired?
2
Answers
What you could do is set up a parallel branch in your Logic App that waits a minute using the Delay action (https://learn.microsoft.com/en-us/azure/connectors/connectors-native-delay) and then stops running the logic app using the Terminate action (https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-actions-triggers#terminate-action). This assumes that it is reasonable to expect the work to be done in a minute and that no harm comes from terminating the process in the middle.
There is a workaround for this with Defer and Re-fetch logic.
Once your logic app triggers, defer the message right away using an Defer Action.
And finally once all the actions complete(success or failed), re-fetch the deferred message using sequence number and then complete the message.
This way, your message will not be picked up again for processing avoiding parallel execution. Also you can increase your lock duration(maximum 5 minutes) if you expect your flow to run longer.