in src/orchestrations/TaskOrchestrationExecutor.ts [163:222]
private processEvent(event: HistoryEvent): void {
const eventType = event.EventType;
switch (eventType) {
case HistoryEventType.OrchestratorStarted: {
const timestamp = event.Timestamp;
if (timestamp > this.context.currentUtcDateTime) {
this.context.currentUtcDateTime = timestamp;
}
break;
}
case HistoryEventType.ContinueAsNew: {
// The clear all state from the orchestration,
// as if no processing of History had taken place
this.initialize();
break;
}
case HistoryEventType.ExecutionStarted: {
this.tryResumingUserCode();
break;
}
case HistoryEventType.EventSent: {
// The EventSent event requires careful handling because it is re-used among
// CallEntity and WaitForExternalEvent APIs.
// For CallEntity, the EventRaised event that contains that API's result will
// expect a TaskID that is different from the TaskID found at the root of this
// EventSent event. Namely, the TaskID it expects can be found nested in the
// "Input" field of the corresponding EventSent event. Here, we handle that
// edge-case by correcting the expected TaskID in our openTask list.
const key = event.EventId;
const task = this.openTasks[key];
if (task !== undefined) {
if (task.actionObj instanceof CallEntityAction) {
// extract TaskID from Input field
const eventSent = event as EventSentEvent;
const requestMessage = JSON.parse(
eventSent.Input as string
) as RequestMessage;
// Obtain correct Task ID and update the task to be associated with it
const eventId = requestMessage.id;
delete this.openTasks[key];
this.openTasks[eventId] = task;
}
}
break;
}
default:
// If the current event contains task-completion data, we resolve that task to a value
if (eventType in this.eventToTaskValuePayload) {
const [isSuccess, idKey] = this.eventToTaskValuePayload[eventType] as [
boolean,
string
];
// We set the corresponding task's value and attempt to resume the orchestration
this.setTaskValue(event, isSuccess, idKey);
this.tryResumingUserCode();
}
break;
}
}