/// <summary> /// Logs that an event is being raised by an orchestration. /// </summary> /// <param name="source">The sending orchestration instance.</param> /// <param name="raisedEvent">The event-sent event.</param> internal void RaisingEvent(OrchestrationInstance source, EventSentEvent raisedEvent) { if (this.IsStructuredLoggingEnabled) { this.WriteStructuredLog(new LogEvents.RaisingEvent(source, raisedEvent)); } }
/// <summary> /// Logs that an orchestration is sending an event to another orchestration instance. /// </summary> /// <param name="source">The orchestration instance sending the event.</param> /// <param name="eventSentEvent">The event being sent.</param> internal void SendingEvent(OrchestrationInstance source, EventSentEvent eventSentEvent) { if (this.IsStructuredLoggingEnabled) { // We re-use the existing RaisingEvent log event for this this.WriteStructuredLog(new LogEvents.RaisingEvent(source, eventSentEvent)); } }
public void HandleEventSentEvent(EventSentEvent eventSentEvent) { int taskId = eventSentEvent.EventId; if (this.orchestratorActionsMap.ContainsKey(taskId)) { this.orchestratorActionsMap.Remove(taskId); } else { throw new NonDeterministicOrchestrationException(eventSentEvent.EventId, $"EventSentEvent: {eventSentEvent.EventId} {eventSentEvent.EventType} {eventSentEvent.Name} {eventSentEvent.InstanceId}"); } }
static TaskMessage ProcessSendEventDecision( SendEventOrchestratorAction sendEventAction, OrchestrationRuntimeState runtimeState) { var historyEvent = new EventSentEvent(sendEventAction.Id) { InstanceId = sendEventAction.Instance.InstanceId, Name = sendEventAction.EventName, Input = sendEventAction.EventData }; runtimeState.AddEvent(historyEvent); return(new TaskMessage { OrchestrationInstance = sendEventAction.Instance, Event = new EventRaisedEvent(-1, sendEventAction.EventData) { Name = sendEventAction.EventName } }); }
public void HandleEventSentEvent(EventSentEvent eventSentEvent) { int taskId = eventSentEvent.EventId; if (!this.orchestratorActionsMap.ContainsKey(taskId)) { throw new NonDeterministicOrchestrationException(eventSentEvent.EventId, $"A previous execution of this orchestration scheduled a send event task with sequence ID {taskId}, " + $"type '{eventSentEvent.EventType}' name '{eventSentEvent.Name}', instance ID '{eventSentEvent.InstanceId}', " + $"but the current replay execution hasn't (yet?) scheduled this task. Was a change made to the orchestrator code " + $"after this instance had already started running?"); } var orchestrationAction = this.orchestratorActionsMap[taskId]; if (!(orchestrationAction is SendEventOrchestratorAction currentReplayAction)) { throw new NonDeterministicOrchestrationException(eventSentEvent.EventId, $"A previous execution of this orchestration scheduled a send event task with sequence ID {taskId}, " + $"type '{eventSentEvent.EventType}', name '{eventSentEvent.Name}', instance ID '{eventSentEvent.InstanceId}', " + $"but the current orchestration replay instead scheduled a {orchestrationAction.GetType().Name} task " + "at this sequence number. Was a change made to the orchestrator code after this instance had already " + "started running?"); } if (!string.Equals(eventSentEvent.Name, currentReplayAction.EventName, StringComparison.OrdinalIgnoreCase)) { throw new NonDeterministicOrchestrationException(eventSentEvent.EventId, $"A previous execution of this orchestration scheduled a send event task with sequence ID {taskId}, " + $"type '{eventSentEvent.EventType}', name '{eventSentEvent.Name}', instance ID '{eventSentEvent.InstanceId}'), " + $"but the current orchestration replay instead scheduled a send event task with name {currentReplayAction.EventName}" + "at this sequence number. Was a change made to the orchestrator code after this instance had already " + "started running?"); } this.orchestratorActionsMap.Remove(taskId); }
public static HistoryEvent GetHistoryEvent(this DbDataReader reader, bool isOrchestrationHistory = false) { string eventTypeString = (string)reader["EventType"]; if (!Enum.TryParse(eventTypeString, out EventType eventType)) { throw new InvalidOperationException($"Unknown event type '{eventTypeString}'."); } int eventId = GetTaskId(reader); HistoryEvent historyEvent; switch (eventType) { case EventType.ContinueAsNew: historyEvent = new ContinueAsNewEvent(eventId, GetPayloadText(reader)); break; case EventType.EventRaised: historyEvent = new EventRaisedEvent(eventId, GetPayloadText(reader)) { Name = GetName(reader), }; break; case EventType.EventSent: historyEvent = new EventSentEvent(eventId) { Input = GetPayloadText(reader), Name = GetName(reader), InstanceId = GetInstanceId(reader), }; break; case EventType.ExecutionCompleted: historyEvent = new ExecutionCompletedEvent( eventId, result: GetPayloadText(reader), orchestrationStatus: OrchestrationStatus.Completed); break; case EventType.ExecutionFailed: historyEvent = new ExecutionCompletedEvent( eventId, result: GetPayloadText(reader), orchestrationStatus: OrchestrationStatus.Failed); break; case EventType.ExecutionStarted: historyEvent = new ExecutionStartedEvent(eventId, GetPayloadText(reader)) { Name = GetName(reader), OrchestrationInstance = new OrchestrationInstance { InstanceId = GetInstanceId(reader), ExecutionId = GetExecutionId(reader), }, Tags = null, // TODO Version = GetVersion(reader), }; string?parentInstanceId = GetParentInstanceId(reader); if (parentInstanceId != null) { ((ExecutionStartedEvent)historyEvent).ParentInstance = new ParentInstance { OrchestrationInstance = new OrchestrationInstance { InstanceId = parentInstanceId }, TaskScheduleId = GetTaskId(reader) }; } break; case EventType.ExecutionTerminated: historyEvent = new ExecutionTerminatedEvent(eventId, GetPayloadText(reader)); break; case EventType.GenericEvent: historyEvent = new GenericEvent(eventId, GetPayloadText(reader)); break; case EventType.OrchestratorCompleted: historyEvent = new OrchestratorCompletedEvent(eventId); break; case EventType.OrchestratorStarted: historyEvent = new OrchestratorStartedEvent(eventId); break; case EventType.SubOrchestrationInstanceCompleted: historyEvent = new SubOrchestrationInstanceCompletedEvent(eventId, GetTaskId(reader), GetPayloadText(reader)); break; case EventType.SubOrchestrationInstanceCreated: historyEvent = new SubOrchestrationInstanceCreatedEvent(eventId) { Input = GetPayloadText(reader), InstanceId = null, // TODO Name = GetName(reader), Version = null, }; break; case EventType.SubOrchestrationInstanceFailed: historyEvent = new SubOrchestrationInstanceFailedEvent( eventId, taskScheduledId: GetTaskId(reader), reason: GetReason(reader), details: GetPayloadText(reader)); break; case EventType.TaskCompleted: historyEvent = new TaskCompletedEvent( eventId, taskScheduledId: GetTaskId(reader), result: GetPayloadText(reader)); break; case EventType.TaskFailed: historyEvent = new TaskFailedEvent( eventId, taskScheduledId: GetTaskId(reader), reason: GetReason(reader), details: GetPayloadText(reader)); break; case EventType.TaskScheduled: historyEvent = new TaskScheduledEvent(eventId) { Input = GetPayloadText(reader), Name = GetName(reader), Version = GetVersion(reader), }; break; case EventType.TimerCreated: historyEvent = new TimerCreatedEvent(eventId) { FireAt = GetVisibleTime(reader), }; break; case EventType.TimerFired: historyEvent = new TimerFiredEvent(eventId) { FireAt = GetVisibleTime(reader), TimerId = GetTaskId(reader), }; break; default: throw new InvalidOperationException($"Don't know how to interpret '{eventType}'."); } historyEvent.Timestamp = GetTimestamp(reader); historyEvent.IsPlayed = isOrchestrationHistory && (bool)reader["IsPlayed"]; return(historyEvent); }