in src/WebJobs.Extensions.DurableTask/Listener/OutOfProcOrchestrationShim.cs [109:191]
private Task InvokeAPIFromAction(AsyncAction action, SchemaVersion schema)
{
Task fireAndForgetTask = Task.CompletedTask;
Task task = null;
switch (action.ActionType)
{
case AsyncActionType.CallActivity:
task = this.context.CallActivityAsync(action.FunctionName, action.Input);
break;
case AsyncActionType.CreateTimer:
DurableOrchestrationContext ctx = this.context as DurableOrchestrationContext;
using (var cts = new CancellationTokenSource())
{
if (ctx != null && schema < SchemaVersion.V3)
{
ctx.ThrowIfInvalidTimerLengthForStorageProvider(action.FireAt);
}
task = this.context.CreateTimer(action.FireAt, cts.Token);
if (action.IsCanceled)
{
cts.Cancel();
}
}
break;
case AsyncActionType.CallActivityWithRetry:
task = this.context.CallActivityWithRetryAsync(action.FunctionName, action.RetryOptions, action.Input);
break;
case AsyncActionType.CallSubOrchestrator:
task = this.context.CallSubOrchestratorAsync(action.FunctionName, action.InstanceId, action.Input);
break;
case AsyncActionType.CallSubOrchestratorWithRetry:
task = this.context.CallSubOrchestratorWithRetryAsync(action.FunctionName, action.RetryOptions, action.InstanceId, action.Input);
break;
case AsyncActionType.CallEntity:
{
var entityId = EntityId.GetEntityIdFromSchedulerId(action.InstanceId);
task = this.context.CallEntityAsync(entityId, action.EntityOperation, action.Input);
break;
}
case AsyncActionType.SignalEntity:
{
// We do not add a task because this is 'fire and forget'
var entityId = EntityId.GetEntityIdFromSchedulerId(action.InstanceId);
this.context.SignalEntity(entityId, action.EntityOperation, action.Input);
task = fireAndForgetTask;
break;
}
case AsyncActionType.ScheduledSignalEntity:
{
// We do not add a task because this is 'fire and forget'
var entityId = EntityId.GetEntityIdFromSchedulerId(action.InstanceId);
this.context.SignalEntity(entityId, action.FireAt, action.EntityOperation, action.Input);
task = fireAndForgetTask;
break;
}
case AsyncActionType.ContinueAsNew:
this.context.ContinueAsNew(action.Input);
task = fireAndForgetTask;
break;
case AsyncActionType.WaitForExternalEvent:
task = this.context.WaitForExternalEvent<object>(action.ExternalEventName);
break;
case AsyncActionType.CallHttp:
task = this.context.CallHttpAsync(action.HttpRequest);
break;
case AsyncActionType.WhenAll:
task = Task.WhenAll(action.CompoundActions.Select(x => this.InvokeAPIFromAction(x, schema)));
break;
case AsyncActionType.WhenAny:
task = Task.WhenAny(action.CompoundActions.Select(x => this.InvokeAPIFromAction(x, schema)));
break;
default:
throw new Exception($"Received an unexpected action type from the out-of-proc function: '${action.ActionType}'.");
}
return task;
}