Skip to content

Instantly share code, notes, and snippets.

@marcduiker
Created September 16, 2020 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcduiker/5be7231212137c85d6827fb91159bd94 to your computer and use it in GitHub Desktop.
Save marcduiker/5be7231212137c85d6827fb91159bd94 to your computer and use it in GitHub Desktop.
Escalate calls orchestrator with time out.
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DurableFunctions.Demo.DotNetCore.EscalateCalls
{
public class EscalateCallsOrchestrator
{
[FunctionName(nameof(EscalateCallsOrchestrator))]
public async Task Run(
[OrchestrationTrigger] IDurableOrchestrationContext context,
ILogger logger)
{
var maxWaitTimePerCall = TimeSpan.FromMinutes(5);
await context.CallActivityAsync("MakeCall", "phonenumber1");
// Orchestrator will wait until Call1 event is received or maxWaitTime is passed.
var resultCall1 = await context.WaitForExternalEvent<bool>("Call1", maxWaitTimePerCall, false);
if (!resultCall1)
{
// Call1 has not been received within maxWaitTime. Let's try Call2.
await context.CallActivityAsync("MakeCall", "phonenumber2");
// Orchestrator will wait until Call2 event is received or maxWaitTime is passed.
var resultCall2 = await context.WaitForExternalEvent<bool>("Call2", maxWaitTimePerCall, false);
if (!resultCall2)
{
// Call2 has not been received within maxWaitTime. Let's try Call3.
await context.CallActivityAsync("MakeCall", "phonenumber3");
// Orchestrator will wait until Call3 event is received or maxWaitTime is passed.
var resultCall3 = await context.WaitForExternalEvent<bool>("Call3", maxWaitTimePerCall, false);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment