protected override void EndProcessing() { var privateData = (Hashtable)MyInvocation.MyCommand.Module.PrivateData; _context = (OrchestrationContext)privateData[SetFunctionInvocationContextCommand.ContextKey]; _context.Actions.Add(new List <OrchestrationAction> { new CallActivityAction(FunctionName, Input) }); var taskScheduled = _context.History.FirstOrDefault( e => e.EventType == HistoryEventType.TaskScheduled && e.Name == FunctionName && !e.IsProcessed); var taskCompleted = taskScheduled == null ? null : _context.History.FirstOrDefault( e => e.EventType == HistoryEventType.TaskCompleted && e.TaskScheduledId == taskScheduled.EventId); if (taskCompleted != null) { taskScheduled.IsProcessed = true; taskCompleted.IsProcessed = true; WriteObject(TypeExtensions.ConvertFromJson(taskCompleted.Result)); } else { _context.ActionEvent.Set(); _waitForStop.WaitOne(); } }
private static object GetEventResult(HistoryEvent historyEvent) { // Output the result if and only if the history event is a completed activity function or a raised external event if (historyEvent.EventType == HistoryEventType.TaskCompleted) { return(TypeExtensions.ConvertFromJson(historyEvent.Result)); } else if (historyEvent.EventType == HistoryEventType.EventRaised) { return(TypeExtensions.ConvertFromJson(historyEvent.Input)); } return(null); }
public void StopAndInitiateDurableTaskOrReplay( DurableTask task, OrchestrationContext context, bool noWait, Action <object> output, Action <string> onFailure, RetryOptions retryOptions = null) { context.OrchestrationActionCollector.Add(task.CreateOrchestrationAction()); if (noWait) { output(task); } else { context.OrchestrationActionCollector.NextBatch(); var scheduledHistoryEvent = task.GetScheduledHistoryEvent(context); var completedHistoryEvent = task.GetCompletedHistoryEvent(context, scheduledHistoryEvent); // We must check if the task has been completed first, otherwise external events will always wait upon replays if (completedHistoryEvent != null) { CurrentUtcDateTimeUpdater.UpdateCurrentUtcDateTime(context); if (scheduledHistoryEvent != null) { scheduledHistoryEvent.IsProcessed = true; } completedHistoryEvent.IsProcessed = true; switch (completedHistoryEvent.EventType) { case HistoryEventType.TaskCompleted: var eventResult = GetEventResult(completedHistoryEvent); if (eventResult != null) { output(eventResult); } break; case HistoryEventType.TaskFailed: if (retryOptions == null) { onFailure(completedHistoryEvent.Reason); } else { // Reset IsProcessed, let RetryProcessor handle these events instead. scheduledHistoryEvent.IsProcessed = false; completedHistoryEvent.IsProcessed = false; var shouldContinueProcessing = RetryProcessor.Process( context.History, scheduledHistoryEvent, retryOptions.MaxNumberOfAttempts, onSuccess: result => { output(TypeExtensions.ConvertFromJson(result)); }, onFailure); if (shouldContinueProcessing) { InitiateAndWaitForStop(context); } } break; } } else { InitiateAndWaitForStop(context); } } }
private static object GetEventResult(HistoryEvent historyEvent) { return(TypeExtensions.ConvertFromJson(historyEvent.Result)); }