0
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?

nmrlqa4
  • 659
  • 1
  • 9
  • 32
  • I don't think you can "start" a timer triggered function. It will always run at the interval set with the cron-string. – abydal Aug 22 '18 at 12:08
  • Ok, I may leave it running all the time, but how to pass a parameter to it? – nmrlqa4 Aug 22 '18 at 12:23
  • For a timertriggered function the best way is to make the function query some other service, queue or db to retrieve the data needed for processing. Perhaps you should use an HttpTriggered function instead? See https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook – abydal Aug 22 '18 at 12:29

1 Answers1

1

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
}
Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107