gpt4 book ai didi

Azure计时器触发器在.net 5独立函数应用程序中不起作用

转载 作者:行者123 更新时间:2023-12-02 07:32:49 25 4
gpt4 key购买 nike

Azure 计时器触发器在 .net 5 独立函数应用程序中无法使用 CRON 表达式每分钟触发一次。如果我们在本地 Visual Studio 中运行它,则效果很好。

公共(public)静态类NotificationScheduler{

[函数(“NotificationScheduler”)]

    public static void Run([TimerTrigger("1-2 * * * * *")] MyInfo myTimer, FunctionContext context)
{

var logger = context.GetLogger("NotificationScheduler");
logger.LogInformation($"Notification Scheduler trigger function executed at: {DateTime.Now}");
//logger.LogInformation($"Next timer schedule at: {myTimer.ScheduleStatus.Next}");


}
}

最佳答案

根据您的要求,我已经在本地环境中运行了该函数,并且它对我来说运行良好,下面是我的引用代码,请根据您的环境进行相应的更改。

  1. 在 Azure 门户中创建了函数应用

enter image description here2.下面是我在函数应用程序中使用的代码

enter image description here

Function1.cs

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


namespace KrishFuncTimerTriggerApp
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 * * * * *")]TimerInfo myTimer, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
}


}
  • 然后我转到Code+Integration,当我进行测试运行时,我的函数应用程序按照我的逻辑每分钟运行一次
  • enter image description here

  • 如下图所示,不支持在 Azure 门户中编辑 .Net 隔离函数。
  • enter image description here

    此外,请尝试按照此 SO 检查您的 SDK 版本和 blog如果您使用预览版中的 SDK 版本“6.0.100-preview.7.21379.14”,则可能是您的函数应用无法工作的原因,如果是这种情况,请尝试降级您的函数应用程序。

    另请检查Cron expression link了解更多详情

    关于Azure计时器触发器在.net 5独立函数应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69996148/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com