2
votes

I have an Azure function in Visual Studio:

    [FunctionName("MyQueueProcessor")]
    [StorageAccount("StorageConnectionString")]
    public static async Task ProcessQueueMessage([QueueTrigger("my-queue")] string message, TextWriter log)
    {
        logInfo("Start processing message", LogLevel.TRACE, message, log);
    }

I have StorageConnectionString set in the Application Settings in the cloud, and when I upload the function from Visual Studio to an Azure App, the function initially runs without issues.

The problem is that the function app restarts frequently, and sometimes when it restarts, the function doesn't run. From looking at Application Insights, I get the following error:

The following 2 functions are in error: ProcessQueueMessage: Microsoft.Azure.WebJobs.Host: Error indexing method 'MyQueueTrigger.ProcessQueueMessage'. Microsoft.Azure.WebJobs.Host: Microsoft Azure WebJobs SDK 'StorageConnectionString' connection string is missing or empty. The Microsoft Azure Storage account connection string can be set in the following ways: 1. Set the connection string named 'StorageConnectionString' in the connectionStrings section of the .config file in the following format , or 2. Set the environment variable named 'StorageConnectionString', or 3. Set corresponding property of JobHostConfiguration. Run: Microsoft.Azure.WebJobs.Host: Error indexing method 'MyTimerTrigger.Run'. Microsoft.Azure.WebJobs.Host: Microsoft Azure WebJobs SDK 'StorageConnectionString' connection string is missing or empty. The Microsoft Azure Storage account connection string can be set in the following ways: 1. Set the connection string named 'StorageConnectionString' in the connectionStrings section of the .config file in the following format , or 2. Set the environment variable named 'StorageConnectionString', or 3. Set corresponding property of JobHostConfiguration.

It appears that sometimes when the function app restarts, the binding to StorageConnectionString fails. How can I prevent this from being an issue?

1
You can try the two methods. 1. set the StorageConnectionString in the local.settings.json file and publish the function again 2.set Always On in the Application Settings in the portalJoy Wang-MSFT
Would local.settings.json really work? I thought that file doesn't get uploaded.Anonymous1
I tried setting "AzureWebJobsStorage": "UseDevelopmentStorage=true", and the function stopped working. I'm guessing it's not possible to have this setup on the consumption plan?Anonymous1
The "AzureWebJobsStorage": "UseDevelopmentStorage=true" is for the emulator, you should specify it as your storage connection string.Joy Wang-MSFT
And the default timeout for functions on a Consumption plan is 5 minutes, the restart may caused by it, refer to this link.Joy Wang-MSFT

1 Answers

0
votes

I converted the code to use the function editor in the portal. I’m not accepting this answer as I’m hopeful someone has a better solution.