Eternal orchestrators are orchestrators that never finish. They are useful when you want to perform a workflow in a loop.
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);
}
}
Eternal orchestrations in Durable Functions
◀ Sub-orchestrations | 🔼 Notify Support Challenge | 🔼 Fraud Detection Challenge | Events ▶