Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Durable Function Invoke without HttpTrigger (Autostart)

Tags:

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!

like image 860
aherrick Avatar asked Feb 09 '19 16:02

aherrick


People also ask

What happens to an azure durable function when the VM hosting the function is rebooted?

Orchestrator functions are durable and reliable. Execution progress is automatically checkpointed when the function "awaits" or "yields". Local state is never lost when the process recycles or the VM reboots. Orchestrator functions can be long-running.

Which type of Azure durable function should you use?

There are currently four durable function types in Azure Functions: activity, orchestrator, entity, and client. The rest of this section goes into more details about the types of functions involved in an orchestration.

Which HTTP response code indicates the orchestration is still in progress select only one answer 200?

HTTP 200 (OK): The specified instance is in a completed or failed state. HTTP 202 (Accepted): The specified instance is in progress.


2 Answers

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.

like image 179
Kzrystof Avatar answered Oct 14 '22 00:10

Kzrystof


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);
    }
like image 35
Michal Grzegorzak Avatar answered Oct 13 '22 23:10

Michal Grzegorzak