定时器触发持久功能时间表

问题描述 投票:0回答:2

我目前正在为我的组织构建一个蔚蓝的持久功能。要求是每个工作日的午夜运行此编排。对于永恒的功能,我们只能提供延迟。我怎样才能通过这样的 cron 表达式来实现这个目标?

我可以创建定时器触发的持久函数吗?有什么限制吗? 或者我应该创建一个 HTTP 触发的持久函数,其中编排器等待外部事件;然后让一个普通的计时器触发 azure 函数根据 Cron 表达式引发该事件?

azure-functions scheduled-tasks azure-durable-functions azure-http-trigger timer-trigger
2个回答
1
投票

您可以使用

DurableOrchestrationClient
输入绑定定义计时器触发的功能。请参阅以下声明样本:

[FunctionName("TimerDurableFunctionStarter")]
public static async Task Run(
    [TimerTrigger("0 */1 * * * *")] TimerInfo info,
    [DurableClient] IDurableOrchestrationClient timerDurableOrchestratorStarter)
{
   string instanceId = await timerDurableOrchestratorStarter.StartNewAsync("<<OrchestratorFunctionName>>");
}

0
投票

如果使用 dotnet 隔离的持久功能,您必须将客户端的类型更改为 DurableTaskClient

触发编排的示例计时器(当转移到生产环境时,请考虑将“RunOnStartup”更改为 false,以避免对功能扩展产生不必要的影响)。

     [Function("TimerStart")]
        public async Task TimerStart(
         [TimerTrigger("0 */15 * * * *", RunOnStartup = true)] TimerInfo myTimer,
           [DurableClient] DurableTaskClient client,
           FunctionContext executionContext)
        {
            ILogger logger = executionContext.GetLogger("TimerStart");

            string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(
                nameof(MyOrchestration));

            logger.LogInformation("Timer started orchestration with ID = '{instanceId}'.", instanceId);

            if (myTimer.ScheduleStatus is not null)
            {
                logger.LogInformation($"Next timer schedule at: {myTimer.ScheduleStatus.Next}");
            }

        }

 
© www.soinside.com 2019 - 2024. All rights reserved.