Azure Functions, Blob Triggers and Timers

This is a short blog post to discuss an issue that has been found with Azure Functions and a very quick workaround that seems to fix the issue.

If you have been enjoying playing with Azure Functions and have been using them in the Consumption service plan (pay-as-you-go), then there is a chance you may have encountered this problem, although you may not have realised it.

A standard use case for Blob triggers is to process some information contained in a file uploaded to Blob storage, for example processing images or taking action on information contained in an uploaded JSON file.

The trigger fires each time a file is uploaded to an attached storage account, but the issue comes when you close your browser or navigate away from the Function App blade in the portal.

Under these circumstances, the Function App eventually spins down and the trigger no longer fires.

There has been a GitHib issue raised for this but the fix is yet to be rolled out.

The fix that seems to work for this is to create a Timer Trigger function within the Function App, as this seems to ensure the Function App remains running.

So when I need to process files, I simply create a function called KeepAlive, that uses the standard C# Timer Trigger template.

You don’t need to amend the code from the template, just set the cron expression to fire when required, I set mine to 9 minutes and that seems to work as I get files every 10 minutes, so for me that means an expression of “0 */9 * * * *”. I have tried up to 15 minutes and that still works.

NOTE: There is a delay the first time the processing function runs again if it has been a while since you went to the Function App blade, so this is not going to work for time critical processing.

NOTE: Obviously you get charged for each execution so this will increase cost, but then you cannot really put a price on the cost of peace of mind that your Function is operating correctly.