0

Azure function will not pick up CRON schedule from Appsettings files in Azure; it only works wen running locally via Visual Studio. I have to create schedules under Configuration section as shown in screen shot below. I would like to use appsettings to simply Deployment.

Thanks in advance.

[enter image description here](https://i.stack.imgur.com/L0H36.png)

I tried defining them in Appsettings files, and I get the following error.
"Error indexing method 'Functions.GetData' '%Schedule_GetData%' does not resolve to a value."

Pravallika KV
  • 2,415
  • 2
  • 2
  • 7
Yonas
  • 1
  • 1
  • `Schedule_GetData` must be added to configuration with its value – thanzeel Feb 02 '23 at 20:03
  • Hi Thanzeel, thank you for your response. We are trying to get it to work with out adding the Cron expression to Configuration Menu > Application Settings of the Azure Portal Function App. Basically we are trying to eliminate using Arm template and have it pick up the schedule from .setings.json file like it does when running locally it gets schedule from local.settings.json. For example for our staging environment we want to use staging.settings.json instead adding the schedule to Configuration Menu > Application Settings of the Azure Portal Function App – Yonas Feb 06 '23 at 15:47

1 Answers1

0

As @thanzeel said, it seems to be the CRON Expression Name is missing in the Function App Configuration Menu - App Settings.

Schedule_GetData must be added to configuration with its value

I have reproduced in my local and cloud environment; it is working good with below configuration with.NET 6 Function App:

Function Code:

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace PravuNet6TTFunApp
{
    public class Function1
    {
        [FunctionName("Function1")]
        public void Run([TimerTrigger("%Schedule_GetData%")]TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        }
    }
}

local.settings.json:

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "Schedule_GetData": "0 */1 * * * *"
  }
}

Before Publishing to the Azure Portal Function App, Added the Same Local App Setting (Cron Expression) to the Configuration Menu > Application Settings of the Azure Portal Function App.

enter image description here

Pravallika KV
  • 2,415
  • 2
  • 2
  • 7
  • Hi Pravallika, thank you for your response. We are trying to get it to work with out adding the Cron expression to Configuration Menu > Application Settings of the Azure Portal Function App. Basically we are trying to eliminate using Arm template and have it pick up the schedule from .setings.json file like it does when running locally it gets schedule from local.settings.json. For example for our staging environment we want to use staging.settings.json instead adding the schedule to Configuration Menu > Application Settings of the Azure Portal Function App. – Yonas Feb 06 '23 at 15:40
  • In the portal Function App > Configuration Menu > Edit/Create the App Setting of CRON Expression >Select the **deployment setting** before Saving. So that application setting is applicable to both the environments (staging and production slots). That setting will not be overridden even when you swap function project between the environments if that app setting is checked with deployment slot setting. Refer SO #[71789955](https://stackoverflow.com/questions/71789955/deployment-slots-in-azure-functionapp). – Pravallika KV Feb 06 '23 at 17:15