internal override HistoryEvent GetCompletedHistoryEvent(OrchestrationContext context, HistoryEvent taskScheduled) { return(context.History.FirstOrDefault( e => e.EventType == HistoryEventType.EventRaised && e.Name == ExternalEventName && !e.IsProcessed)); }
internal override HistoryEvent GetCompletedHistoryEvent(OrchestrationContext context, HistoryEvent scheduledHistoryEvent) { return(scheduledHistoryEvent == null ? null : context.History.FirstOrDefault( e => e.EventType == HistoryEventType.TimerFired && e.TimerId == scheduledHistoryEvent.EventId)); }
private static HistoryEvent GetTaskCompletedHistoryEvent(OrchestrationContext context, HistoryEvent taskScheduled) { return(taskScheduled == null ? null : context.History.FirstOrDefault( e => e.EventType == HistoryEventType.TaskCompleted && e.TaskScheduledId == taskScheduled.EventId)); }
private static object GetEventResult(HistoryEvent historyEvent) { return(TypeExtensions.ConvertFromJson(historyEvent.Result)); }
// Returns true to indicate that processing this activity invocation should continue. public static bool Process( HistoryEvent[] history, HistoryEvent firstTaskScheduledEvent, int maxNumberOfAttempts, Action <string> onSuccess, Action <string> onFinalFailure) { var firstTaskScheduledEventIndex = FindEventIndex(history, firstTaskScheduledEvent); // Inspired by https://github.com/Azure/azure-functions-durable-js/commit/d789181234ace85df51ce8a849f15b7c8ae2a4f1 var attempt = 1; HistoryEvent taskScheduled = null; HistoryEvent taskFailed = null; HistoryEvent taskRetryTimer = null; for (var i = firstTaskScheduledEventIndex; i < history.Length; i++) { var historyEvent = history[i]; if (historyEvent.IsProcessed) { continue; } if (taskScheduled == null) { if (historyEvent.EventType == HistoryEventType.TaskScheduled) { taskScheduled = historyEvent; } continue; } if (historyEvent.EventType == HistoryEventType.TaskCompleted) { if (historyEvent.TaskScheduledId == taskScheduled.EventId) { taskScheduled.IsProcessed = true; historyEvent.IsProcessed = true; onSuccess(historyEvent.Result); return(false); } else { continue; } } if (taskFailed == null) { if (historyEvent.EventType == HistoryEventType.TaskFailed) { if (historyEvent.TaskScheduledId == taskScheduled.EventId) { taskFailed = historyEvent; } } continue; } if (taskRetryTimer == null) { if (historyEvent.EventType == HistoryEventType.TimerCreated) { taskRetryTimer = historyEvent; } else { continue; } } if (historyEvent.EventType == HistoryEventType.TimerFired) { if (historyEvent.TimerId == taskRetryTimer.EventId) { taskScheduled.IsProcessed = true; taskFailed.IsProcessed = true; taskRetryTimer.IsProcessed = true; historyEvent.IsProcessed = true; if (attempt >= maxNumberOfAttempts) { onFinalFailure(taskFailed.Reason); return(false); } else { attempt++; taskScheduled = null; taskFailed = null; taskRetryTimer = null; } } else { continue; } } } return(true); }