"Error indexing method 'Functions.GetData' '%Schedule_GetData%' does not resolve to a value."
AS @thanzeel说,似乎是函数应用程序配置菜单中缺少cron表达式名称 - 应用程序设置。
Schedule_GetData
必须添加与其值的配置 我已经在我的本地和云环境中复制了;它可以与以下配置一起使用。NET6功能应用程序:
功能代码:
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 * * * *"
}
}
在发布到Azure Portal函数应用程序之前,将相同的本地应用程序设置(CRON表达式)添加到“配置”菜单> Azure Portal函数应用程序的应用程序设置。
Feb2025更新: 对于那些愿意使用Release Pipeline(Legacy/YAML)的人,在“ Azure App Service部署”或“ Azure函数部署”任务中,在“应用程序和配置设置”下,您可以使用变量设置这些值。
例如:
-TimerSchedule "$(TimerSchedule)"
功能将具有此注释:
[Function("TimerFunction")]
public void Run([TimerTrigger("%TimerSchedule%")] TimerInfo myTimer)
{
var schedule = _configuration["TimerSchedule"];
_logger.LogInformation($"Timer trigger function executed at: {DateTime.Now}, Schedule: {schedule}");
}
,但是,对于本地运行,您需要使用local.settings.json在“值”部分下,因为本地跑步者仅知道'local.settings.json'!!
{
"Values": {
"TimerSchedule": "0 */5 * * * *"
}
}