in src/WebJobs.Extensions.DurableTask/LocalGrpcListener.cs [158:217]
public async override Task<P.CreateInstanceResponse> StartInstance(P.CreateInstanceRequest request, ServerCallContext context)
{
try
{
// Create the orchestration instance
var instance = new OrchestrationInstance
{
InstanceId = request.InstanceId ?? Guid.NewGuid().ToString("N"),
ExecutionId = Guid.NewGuid().ToString(),
};
// Create the ExecutionStartedEvent
ExecutionStartedEvent executionStartedEvent = new ExecutionStartedEvent(-1, request.Input)
{
Name = request.Name,
Version = request.Version,
OrchestrationInstance = instance,
ScheduledStartTime = request.ScheduledStartTimestamp?.ToDateTime(),
};
// Get the parent trace context from CreateInstanceRequest
string? traceParent = request.ParentTraceContext?.TraceParent;
string? traceState = request.ParentTraceContext?.TraceState;
// Create a new activity with the parent context
ActivityContext.TryParse(traceParent, traceState, out ActivityContext parentActivityContext);
using Activity? scheduleOrchestrationActivity = StartActivityForNewOrchestration(executionStartedEvent, parentActivityContext);
// Schedule the orchestration
await this.GetDurabilityProvider(context).CreateTaskOrchestrationAsync(
new TaskMessage
{
Event = executionStartedEvent,
OrchestrationInstance = instance,
},
this.GetStatusesNotToOverride());
return new P.CreateInstanceResponse
{
InstanceId = instance.InstanceId,
};
}
catch (OrchestrationAlreadyExistsException)
{
throw new RpcException(new Status(StatusCode.AlreadyExists, $"An Orchestration instance with the ID {request.InstanceId} already exists."));
}
catch (InvalidOperationException ex) when (ex.Message.EndsWith("already exists.")) // for older versions of DTF.AS and DTFx.Netherite
{
throw new RpcException(new Status(StatusCode.AlreadyExists, $"An Orchestration instance with the ID {request.InstanceId} already exists."));
}
catch (Exception ex)
{
this.extension.TraceHelper.ExtensionWarningEvent(
this.extension.Options.HubName,
functionName: request.Name,
instanceId: request.InstanceId,
message: $"Failed to start instanceId {request.InstanceId} due to internal exception.\n Exception trace: {ex}.");
throw new RpcException(new Status(StatusCode.Internal, $"Failed to start instance with ID {request.InstanceId}.\nInner Exception message: {ex.Message}."));
}
}