in src/DurableTask.Core/TaskHubClient.cs [625:712]
async Task<OrchestrationInstance> InternalCreateOrchestrationInstanceWithRaisedEventAsync(
string orchestrationName,
string orchestrationVersion,
string? orchestrationInstanceId,
object? orchestrationInput,
IDictionary<string, string>? orchestrationTags,
OrchestrationStatus[]? dedupeStatuses,
string? eventName,
object? eventData,
DateTime? startAt = null)
{
TraceContextBase? requestTraceContext = null;
// correlation
CorrelationTraceClient.Propagate(()=> { requestTraceContext = CreateOrExtractRequestTraceContext(eventName); });
if (string.IsNullOrWhiteSpace(orchestrationInstanceId))
{
orchestrationInstanceId = Guid.NewGuid().ToString("N");
}
var orchestrationInstance = new OrchestrationInstance
{
InstanceId = orchestrationInstanceId,
ExecutionId = Guid.NewGuid().ToString("N"),
};
string serializedOrchestrationData = this.defaultConverter.SerializeInternal(orchestrationInput);
ExecutionStartedEvent startedEvent = new ExecutionStartedEvent(-1, serializedOrchestrationData)
{
Tags = orchestrationTags,
Name = orchestrationName,
Version = orchestrationVersion,
OrchestrationInstance = orchestrationInstance,
ScheduledStartTime = startAt
};
TaskMessage startMessage = new TaskMessage
{
OrchestrationInstance = orchestrationInstance,
Event = startedEvent
};
this.logHelper.SchedulingOrchestration(startedEvent);
using Activity? newActivity = TraceHelper.StartActivityForNewOrchestration(startedEvent);
CorrelationTraceClient.Propagate(() => CreateAndTrackDependencyTelemetry(requestTraceContext));
try
{
// Raised events and create orchestration calls use different methods so get handled separately
await this.ServiceClient.CreateTaskOrchestrationAsync(startMessage, dedupeStatuses);
}
catch (Exception e)
{
TraceHelper.AddErrorDetailsToSpan(newActivity, e);
throw;
}
if (eventData != null)
{
string serializedEventData = this.defaultConverter.SerializeInternal(eventData);
var eventRaisedEvent = new EventRaisedEvent(-1, serializedEventData) { Name = eventName };
this.logHelper.RaisingEvent(orchestrationInstance, eventRaisedEvent);
var eventMessage = new TaskMessage
{
OrchestrationInstance = new OrchestrationInstance
{
InstanceId = orchestrationInstanceId,
// to ensure that the event gets raised on the running
// orchestration instance, null the execution id
// so that it will find out which execution
// it should use for processing
ExecutionId = null
},
Event = eventRaisedEvent,
};
await this.ServiceClient.SendTaskOrchestrationMessageAsync(eventMessage);
}
return orchestrationInstance;
}