I want to wait for an external event and send a reminder if the event hasn't occurred in 5 days. I am new to how tasks work. Will the following orchestrator function run as expected? I didn't use Task.WhenAll
as I though this way was simpler:
[FunctionName("Function1")]
public static async Task RunOrchestrator(
[OrchestrationTrigger] IDurableOrchestrationContext context)
{
using (var cts = new CancellationTokenSource())
{
SendReminder(context, cts.Token); // dont await so this happens in the background
await context.WaitForExternalEvent("MyEvent");
cts.Cancel(); // cancel the reminder as the event has now happened
// react to MyEvent ...
}
}
public static async Task SendReminder(IDurableOrchestrationContext context, CancellationToken cancellationToken)
{
await context.CreateTimer(context.CurrentUtcDateTime.AddDays(5), cancellationToken);
await context.CallHttpAsync(...) // http call to ms graph to send a reminder email
}
Do I need to use Task.Run
instead of just directly calling SendReminder
?