nmrlqa4
nmrlqa4

Reputation: 679

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}");
        }
    }
}

I want my Durable Function to start another function that is timer based, which has to reoccur every 5 minutes. So far so good and this is my code. Now I want this activity to start when I call the Durable Function with HTTP call (POST, GET, whatever) (I preferred with Queue but don't know how to do it) and pass a parameter to it and then it passes this parameter to the invoked function. How?

Upvotes: 0

Views: 2271

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35134

You can't "start" Timer Trigger. Orchestrator can only manage Activity functions, like this:

[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
}

Upvotes: 1

Related Questions