5
votes

Within Azure I’ve developed a function (App service) which is triggered when a new csv files is placed in a specific storage account. The function has been developed in Azure and functions without problems each time a new csv file is uploaded. However with CI/CD in mind I’ve decided to move my development process from Azure to Visual Studio (2017).

The code runs without any problems locally, but as soon as I publish the code to Azure (through VSTS) the challenge begins. It seems as if the trigger doesn’t get activated when new csv files are being uploaded to the storage account. Incidentally the function did trigger, but I have not been able to pinpoint why this is, or recreate it.

In order to make the problem more understandable I’ve reduced my code to just the Blobtrigger and some logging. Also I removed the build in VSTS and directly published my build through Visual Studio 2017, but with similar results. The code works fine locally, but after publishing it the function doesn’t get triggered (or does so very incidentally).

The code I used:

using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;

namespace TestApp
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([BlobTrigger("csv-files-in/{name}.csv", Connection = "AzureWebJobsStorage")]Stream myBlob, string name, TraceWriter log)
        {
            log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
        }
    }
}

“AzureWebJobsStorage” refers to a local.settings.json where the endpoint of the Blobstorage is defined. This setting is automatically deployed to Azure, but even if I set this connection manually the function doesn’t get triggered. After many attempts of solving this on my own I’ve decided to ask the smart people on this website for advice. Is this a bug or am I missing something? What can I do to ensure that my function does (reliably) get triggered after publishing this towards Azure? Thanks in advance.

2
how did you deploy to function ? your connectionstring AzureWebJobsStorage and also all your settings have be set in the appsettings blade of the function appThomas
I've deployed to the function in 2 different ways. The first deploy was through a build and release in VSTS, the second deploy through a publish in visual studio. All settings from my local.settings file like AzureWebJobsStorage are also set in my app settings. I've also tried placing the 'AzureWebJobsStorage as a connection string instead of an application setting, but without any succesJustWondering
do you have multiple instance of this function running against the same storage account ?Thomas
I do have multiple functions that are triggered by this same storage account yes, but in order to test the deployed function I've disabled all of these. I figured this should prevent them from impacting my deployed function.JustWondering
yeah the function host acquires a lease so it could have been this problem... I guess you will have to add more details or open an issue on githubThomas

2 Answers

0
votes

You're probably hitting this:

If your function app is on the Consumption plan, there can be up to a 10-minute delay in processing new blobs if a function app has gone idle. To avoid this cold-start delay, you can switch to an App Service plan with Always On enabled, or use a different trigger type.

Taken from Azure Blob storage bindings for Azure Functions

An alternative solution to trigger the function is using Event Grid.

Edit:
Also, please be advised a BlobTrigger is a polling trigger. The longer it doesn't find any changes, the longer periods it takes between polls. That gives you some delay that might run up to minutes.

If the blob container being monitored contains more than 10,000 blobs, the Functions runtime scans log files to watch for new or changed blobs. This process can result in delays. A function might not get triggered until several minutes or longer after the blob is created.

More info at Azure Blob storage bindings for Azure Functions - polling

0
votes

I had this problem with an Azure Service Bus triggered function and was able to find the problem by viewing the function logs in Storage Explorer. In my case it was an incorrectly named setting that was causing the problem.