提前感谢

问题描述 投票:0回答:2
我尝试在AppSetting Files中定义它们,我会收到以下错误。

"Error indexing method 'Functions.GetData' '%Schedule_GetData%' does not resolve to a value."

AS @[enter image description here](https://i.sstatic.net/L0H36.png)thanzeel说,似乎是函数应用程序配置菜单中缺少cron表达式名称 - 应用程序设置。


Schedule_GetData

必须添加与其值
的配置

我已经在我的本地和云环境中复制了;它可以与以下配置一起使用。NET6功能应用程序:
c# azure azure-functions
2个回答
0
投票

功能代码

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'!enter image description here

{ "Values": { "TimerSchedule": "0 */5 * * * *" } }

0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.