如何将 POST 参数传递给 Durable Function,然后将此参数传递给 Timer Triggered 函数

How to pass a POST parameter to a Durable Function and then pass this param to a Timer Triggered function

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

namespace mynamespace
{
    public static class myfuncclass
    {
        [FunctionName("mydurablefunc")]
        public static async void Run([OrchestrationTrigger] DurableOrchestrationContextBase context)
        {
            await context.CallActivityAsync<string>("timer", "myparam");
        }

        [FunctionName("timer")]
        public static void RunTimer([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, TraceWriter log)
        {
            if (myTimer.IsPastDue)
            {
                log.Info("Timer is running late!");
            }
            log.Info($"Timer trigger function executed at: {DateTime.Now}");
        }
    }
}

我想让我的持久函数启动另一个基于计时器的函数,它必须每 5 分钟重复一次。到目前为止一切顺利,这是我的代码。现在我希望这个 activity 在我使用 HTTP 调用(POST、GET 等)调用 Durable Function 时启动(我更喜欢 Queue,但不知道该怎么做)并传递一个参数给它,然后它将此参数传递给调用的函数。怎么样?

您不能"start" 定时器触发器。 Orchestrator 只能管理 Activity 个函数,如下所示:

[FunctionName("mydurablefunc")]
public static async void Run([OrchestrationTrigger] DurableOrchestrationContextBase context)
{
    for (int i = 0; i < 10; i++)
    {
        DateTime deadline = context.CurrentUtcDateTime.Add(TimeSpan.FromMinutes(5));
        await context.CreateTimer(deadline, CancellationToken.None);
        await context.CallActivityAsync<string>("myaction", "myparam");
    }
}

[FunctionName("myaction")]
public static Task MyAction([ActivityTrigger] string param)
{
    // do something
}