5
votes

I am looking at this example to run a durable function Activity after a set timeout.

https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-eternal-orchestrations

This will allow my function activity to perform processing of data, then wait exactly 1 hour before it attempts to load again. This will continue to run forever. Perfect.

However, when publishing the Function to Azure, I don't want to have to manually invoke/start the function via the associated HTTP Trigger. I just want the durable function to kickoff automatically and start processing.

Is this possible? If not, what is a suggested work around?

Thanks!

2
Would it do the job if you have a simple Client Function with a Timer Trigger that would kick off your orchestrator?Kzrystof
Otherwise, assuming you are using Azure DevOps, this could be a part of your Release pipeline. Once the Function App is deployed, have a Task that would just poke your HTTP Triggered Function... ?Kzrystof
are you talking about just a timer trigger function that auto started and essentially just ran once to kickoff they orchestrator? Is that possible?aherrick
If I am understanding this correctly, the orchestrator needs to be kicked off by a Client Function. In your case, I think the Client Function could be an HTTP Triggered Client Function (aka The Kicker). The Kicker Function could be called by the release pipeline. Every time you deploy a new version of your Function App, a simple bash script could be called and would call your Kicker, which would start your Orchestrator... Does that make any sense?Kzrystof
Yep it does. Haven’t added this App to pipelines yet but I get what you’re saying. Thanks for the thoughts!aherrick

2 Answers

2
votes

As discussed in the comments, one way of doing this would be to add a new Task in your Release pipeline.

Here is what I understood of your setup from your question:

[FunctionName("ClientFunction")]
public static async Task<HttpResponseMessage> OnHttpTriggerAsync([HttpTrigger(AuthorizationLevel.Anonymous, "post")]
            HttpRequestMessage request, [OrchestrationClient] DurableOrchestrationClient starter, ILogger logger)
{
    // Triggers the orchestrator.
    string instanceId = await starter.StartNewAsync("OrchestratorFunction", null);

    return new HttpResponseMessage(HttpStatusCode.OK);
}


[FunctionName("OrchestratorFunction")]
public static async Task DoOrchestrationThingsAsync([OrchestrationTrigger] DurableOrchestrationContext context, ILogger logger)
{
    DateTime deadline = context.CurrentUtcDateTime.Add(TimeSpan.FromHours(1));
    await context.CreateTimer(deadline, CancellationToken.None);

    // Triggers some yout activity.
    await context.CallActivityAsync("ActivityFunction", null);
}

[FunctionName("ActivityFunction")]
public static Task DoAnAwesomeActivity([ActivityTrigger] DurableActivityContext context)
{
}

Now, every time you deploy a new version of the Function App, you need the orchestrator to be run. However, I do not think it can be started by itself.

What I propose is to have a simple bash script (using curl or something else) that would call the ClientFunction at the appropriate URL.

Bash script

On top of that, one of the nice things of this solution is that you could make the deployment fail if the Azure Function does not respond.

1
votes

This seems to be working too.

[FunctionName("AutoStart")]
public static async Task Run([TimerTrigger("*/5 * * * * *", RunOnStartup = true, UseMonitor = false)]TimerInfo myStartTimer, 
    [DurableClient] IDurableClient orchestrationClient, ILogger log)
    {
        string instanceId = await orchestrationClient.StartNewAsync("Start_Orchestrator", null);
    }