Skip to content

Latest commit

 

History

History
37 lines (26 loc) · 1.48 KB

eternalorchestrations.md

File metadata and controls

37 lines (26 loc) · 1.48 KB

Eternal Orchestrations

Eternal orchestrators are orchestrators that never finish. They are useful when you want to perform a workflow in a loop.

Eternal Orchestrations

You can make a conditional eternal orchestrator that only continues the orchestrator inside an if statement based on logic you provide (e.g. a result of an activity, sub-orchestrator, or event).

In this example a clean up action is performed as long as there are items to clean up:

[FunctionName(nameof(PeriodicCleanupOrchestrator))]
public static async Task Run(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
{
    var itemsToCleanup = context.GetInput<CleanupInput>();

    var updatedItemsToCleanup = await context.CallActivityAsync<CleanupInput>(
        nameof(DoCleanupActivity), 
        itemsToCleanUp);

    if (updatedItemsToCleanup.Any())
    {
        DateTime nextCleanup = context.CurrentUtcDateTime.AddHours(4);
        await context.CreateTimer(nextCleanup, CancellationToken.None);

        context.ContinueAsNew(updatedItemsToCleanup);
    }
}

Official Docs

Eternal orchestrations in Durable Functions


◀ Sub-orchestrations | 🔼 Notify Support Challenge | 🔼 Fraud Detection Challenge | Events ▶