Long execution functions with Service Bus Trigger

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.

Function App under at least a Premium plan could have unlimited execution time. However, it might caused a duplicated invocation issue with a ServiceBus trigger because the "PeekLock" duration is up to 5 minutes (including renew).

 

It is a tutorial to reproduce such the scenario.

 

STEP 1: In Azure portal, create a new Premium python Function App and a Service Bus + Queue

 

STEP 2: Download the sample code and apply some changes.

https://cchlab.blob.core.windows.net/cchlab/cchlabsbf.zip

In "host.json", please specify the Function App timeout and the ServiceBus PeekLock timeout as below.

theringe_0-1661935163508.png

In "ServiceBusQueueTrigger1/function.json", please setup some configuration:

SBQ_STRING=<your service bus queue name>

theringe_1-1661935243996.png

Then, deploy the project to Function App.

 

STEP 3: Making an experiment with a short execution time.

Visit: https://<YourAppName>.azurewebsites.net/api/httptrigger1?t=<DurationInSecond>

Please specify the "DurationInSecond" to 30 this time, and you may see the result like this:

theringe_2-1661935480891.png

We apply this operation to send a message to the ServiceBus queue and told the ServiceBus trigger to pause 30 seconds before execution.

Now, please go to the monitor page:

theringe_3-1661935589300.png

You can see it is just a normal short invocation.

 

STEP 4: Making an experiment with a long execution time.

Visit: https://<YourAppName>.azurewebsites.net/api/httptrigger1?t=<DurationInSecond>

Please specify the "DurationInSecond" to 330 this time, and you may see the result like this:

theringe_4-1661935643333.png

Now, please go to the monitor page:

theringe_5-1661935730040.pngtheringe_6-1661935742067.pngtheringe_7-1661935749235.png

As you can see, there are duplicate invocations with the same message id, which might caused some potential business issues if we ignore them.

 

Conclusion:

Since we cannot adjust "maxAutoRenewDuration" to more than 5 minutes, we could only reduce the execution time from this ServiceBus trigger.

Leave a Reply

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

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.