Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class SendSmsOrchestratorFunction
{
[FunctionName(nameof(SendSmsOrchestratorFunction))]
public async Task SendSmsAsync([OrchestrationTrigger] IDurableOrchestrationContext context)
{
var recipient = context.GetInput<SmsRecipient>();
var status = await context.CallActivityAsync<bool>(nameof(SaveSmsRecipientActivityFunction), recipient);
if (!status)
{
return;
}
using (var cts = new CancellationTokenSource())
{
var timeoutTask = context.CreateTimer(context.CurrentUtcDateTime.AddSeconds(30), cts.Token);
var waitForSmsSendTask = context.WaitForExternalEvent<SmsEvent>("smssentevent");
var retryOptions = new RetryOptions(TimeSpan.FromSeconds(5), 5);
await context.CallActivityWithRetryAsync(nameof(SendSmsActivityFunction), retryOptions, recipient);
var winner = await Task.WhenAny(timeoutTask, waitForSmsSendTask);
if (winner == waitForSmsSendTask)
{
cts.Cancel();
await context.CallActivityAsync(nameof(UpdateSmsRecipientActivityFunction), waitForSmsSendTask.Result);
}
else
{
await context.CallActivityAsync(nameof(UpdateSmsRecipientActivityFunction), new SmsEvent{Id = recipient.Id, Status = RecipientStatus.CouldNotSend});
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.