Search in sources :

Example 1 with EventType

use of com.uber.cadence.EventType in project cadence-client by uber-java.

the class ReplayDecider method decideImpl.

private void decideImpl(Functions.Proc query) throws Throwable {
    try {
        long lastNonReplayedEventId = historyHelper.getLastNonReplayEventId();
        // Buffer events until the next DecisionTaskStarted and then process them
        // setting current time to the time of DecisionTaskStarted event
        HistoryHelper.EventsIterator eventsIterator = historyHelper.getEvents();
        // Looks ahead to the DecisionTaskStarted event to get current time before calling eventLoop.
        do {
            List<HistoryEvent> decisionCompletionToStartEvents = new ArrayList<>();
            while (eventsIterator.hasNext()) {
                HistoryEvent event = eventsIterator.next();
                EventType eventType = event.getEventType();
                if (eventType == EventType.DecisionTaskCompleted) {
                    decisionsHelper.setWorkflowContextData(event.getDecisionTaskCompletedEventAttributes().getExecutionContext());
                } else if (eventType == EventType.DecisionTaskStarted || !eventsIterator.hasNext()) {
                    // Above check for the end of history is to support queries that get histories
                    // without DecisionTaskStarted being the last event.
                    decisionsHelper.handleDecisionTaskStartedEvent();
                    if (!eventsIterator.isNextDecisionFailed()) {
                        // Cadence timestamp is in nanoseconds
                        long replayCurrentTimeMilliseconds = event.getTimestamp() / MILLION;
                        context.setReplayCurrentTimeMilliseconds(replayCurrentTimeMilliseconds);
                        break;
                    }
                } else if (eventType != EventType.DecisionTaskScheduled && eventType != EventType.DecisionTaskTimedOut && eventType != EventType.DecisionTaskFailed) {
                    decisionCompletionToStartEvents.add(event);
                }
            }
            for (HistoryEvent event : decisionCompletionToStartEvents) {
                if (event.getEventId() >= lastNonReplayedEventId) {
                    context.setReplaying(false);
                }
                EventType eventType = event.getEventType();
                processEvent(event, eventType);
            }
            eventLoop();
            mayBeCompleteWorkflow();
        } while (eventsIterator.hasNext());
    } finally {
        if (query != null) {
            query.apply();
        }
        workflow.close();
    }
}
Also used : EventType(com.uber.cadence.EventType) ArrayList(java.util.ArrayList) HistoryEvent(com.uber.cadence.HistoryEvent)

Aggregations

EventType (com.uber.cadence.EventType)1 HistoryEvent (com.uber.cadence.HistoryEvent)1 ArrayList (java.util.ArrayList)1