Search in sources :

Example 1 with HistoryEvent

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

the class WorkflowExecutionUtils method waitForWorkflowInstanceCompletionAcrossGenerations.

/**
 * Like {@link #waitForWorkflowInstanceCompletion(IWorkflowService, String, WorkflowExecution,
 * long, TimeUnit)} , except will wait for continued generations of the original workflow
 * execution too.
 *
 * @see #waitForWorkflowInstanceCompletion(IWorkflowService, String, WorkflowExecution, long,
 *     TimeUnit)
 */
public static WorkflowExecutionCloseStatus waitForWorkflowInstanceCompletionAcrossGenerations(IWorkflowService service, String domain, WorkflowExecution workflowExecution, long timeout, TimeUnit unit) throws InterruptedException, TimeoutException, EntityNotExistsError {
    WorkflowExecution lastExecutionToRun = workflowExecution;
    long millisecondsAtFirstWait = System.currentTimeMillis();
    WorkflowExecutionCloseStatus lastExecutionToRunCloseStatus = waitForWorkflowInstanceCompletion(service, domain, lastExecutionToRun, timeout, unit);
    // keep waiting if the instance continued as new
    while (lastExecutionToRunCloseStatus == WorkflowExecutionCloseStatus.CONTINUED_AS_NEW) {
        // get the new execution's information
        HistoryEvent closeEvent = getInstanceCloseEvent(service, domain, lastExecutionToRun, timeout, unit);
        WorkflowExecutionContinuedAsNewEventAttributes continuedAsNewAttributes = closeEvent.getWorkflowExecutionContinuedAsNewEventAttributes();
        WorkflowExecution newGenerationExecution = new WorkflowExecution();
        newGenerationExecution.setRunId(continuedAsNewAttributes.getNewExecutionRunId());
        newGenerationExecution.setWorkflowId(lastExecutionToRun.getWorkflowId());
        // and wait for it
        long currentTime = System.currentTimeMillis();
        long millisecondsSinceFirstWait = currentTime - millisecondsAtFirstWait;
        long timeoutInSecondsForNextWait = unit.toMillis(timeout) - (millisecondsSinceFirstWait / 1000L);
        lastExecutionToRunCloseStatus = waitForWorkflowInstanceCompletion(service, domain, newGenerationExecution, timeoutInSecondsForNextWait, TimeUnit.MILLISECONDS);
        lastExecutionToRun = newGenerationExecution;
    }
    return lastExecutionToRunCloseStatus;
}
Also used : WorkflowExecutionCloseStatus(com.uber.cadence.WorkflowExecutionCloseStatus) WorkflowExecution(com.uber.cadence.WorkflowExecution) HistoryEvent(com.uber.cadence.HistoryEvent) WorkflowExecutionContinuedAsNewEventAttributes(com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes)

Example 2 with HistoryEvent

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

the class WorkflowContext method getWorkflowStartedEventAttributes.

private WorkflowExecutionStartedEventAttributes getWorkflowStartedEventAttributes() {
    HistoryEvent firstHistoryEvent = decisionTask.getHistory().getEvents().get(0);
    WorkflowExecutionStartedEventAttributes attributes = firstHistoryEvent.getWorkflowExecutionStartedEventAttributes();
    return attributes;
}
Also used : WorkflowExecutionStartedEventAttributes(com.uber.cadence.WorkflowExecutionStartedEventAttributes) HistoryEvent(com.uber.cadence.HistoryEvent)

Example 3 with HistoryEvent

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

the class StateMachines method completeExternalSignal.

private static void completeExternalSignal(RequestContext ctx, SignalExternalData data, String runId, long notUsed) {
    SignalExternalWorkflowExecutionInitiatedEventAttributes initiatedEvent = data.initiatedEvent;
    WorkflowExecution signaledExecution = initiatedEvent.getWorkflowExecution().deepCopy().setRunId(runId);
    ExternalWorkflowExecutionSignaledEventAttributes a = new ExternalWorkflowExecutionSignaledEventAttributes().setInitiatedEventId(data.initiatedEventId).setWorkflowExecution(signaledExecution).setControl(initiatedEvent.getControl()).setDomain(initiatedEvent.getDomain());
    HistoryEvent event = new HistoryEvent().setEventType(EventType.ExternalWorkflowExecutionSignaled).setExternalWorkflowExecutionSignaledEventAttributes(a);
    ctx.addEvent(event);
}
Also used : ExternalWorkflowExecutionSignaledEventAttributes(com.uber.cadence.ExternalWorkflowExecutionSignaledEventAttributes) WorkflowExecution(com.uber.cadence.WorkflowExecution) HistoryEvent(com.uber.cadence.HistoryEvent) SignalExternalWorkflowExecutionInitiatedEventAttributes(com.uber.cadence.SignalExternalWorkflowExecutionInitiatedEventAttributes)

Example 4 with HistoryEvent

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

the class StateMachines method timeoutChildWorkflow.

private static void timeoutChildWorkflow(RequestContext ctx, ChildWorkflowData data, TimeoutType timeoutType, long notUsed) {
    StartChildWorkflowExecutionInitiatedEventAttributes ie = data.initiatedEvent;
    ChildWorkflowExecutionTimedOutEventAttributes a = new ChildWorkflowExecutionTimedOutEventAttributes().setDomain(ie.getDomain()).setStartedEventId(data.startedEventId).setWorkflowExecution(data.execution).setWorkflowType(ie.getWorkflowType()).setTimeoutType(timeoutType).setInitiatedEventId(data.initiatedEventId);
    HistoryEvent event = new HistoryEvent().setEventType(EventType.ChildWorkflowExecutionTimedOut).setChildWorkflowExecutionTimedOutEventAttributes(a);
    ctx.addEvent(event);
}
Also used : StartChildWorkflowExecutionInitiatedEventAttributes(com.uber.cadence.StartChildWorkflowExecutionInitiatedEventAttributes) HistoryEvent(com.uber.cadence.HistoryEvent) ChildWorkflowExecutionTimedOutEventAttributes(com.uber.cadence.ChildWorkflowExecutionTimedOutEventAttributes)

Example 5 with HistoryEvent

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

the class StateMachines method timeoutWorkflow.

private static void timeoutWorkflow(RequestContext ctx, WorkflowData data, TimeoutType timeoutType, long notUsed) {
    WorkflowExecutionTimedOutEventAttributes a = new WorkflowExecutionTimedOutEventAttributes().setTimeoutType(timeoutType);
    HistoryEvent event = new HistoryEvent().setEventType(EventType.WorkflowExecutionTimedOut).setWorkflowExecutionTimedOutEventAttributes(a);
    ctx.addEvent(event);
}
Also used : HistoryEvent(com.uber.cadence.HistoryEvent) ChildWorkflowExecutionTimedOutEventAttributes(com.uber.cadence.ChildWorkflowExecutionTimedOutEventAttributes) WorkflowExecutionTimedOutEventAttributes(com.uber.cadence.WorkflowExecutionTimedOutEventAttributes)

Aggregations

HistoryEvent (com.uber.cadence.HistoryEvent)49 History (com.uber.cadence.History)5 WorkflowExecution (com.uber.cadence.WorkflowExecution)5 GetWorkflowExecutionHistoryRequest (com.uber.cadence.GetWorkflowExecutionHistoryRequest)4 GetWorkflowExecutionHistoryResponse (com.uber.cadence.GetWorkflowExecutionHistoryResponse)3 SignalExternalWorkflowExecutionInitiatedEventAttributes (com.uber.cadence.SignalExternalWorkflowExecutionInitiatedEventAttributes)3 ActivityTaskCompletedEventAttributes (com.uber.cadence.ActivityTaskCompletedEventAttributes)2 ActivityTaskFailedEventAttributes (com.uber.cadence.ActivityTaskFailedEventAttributes)2 ChildWorkflowExecutionTimedOutEventAttributes (com.uber.cadence.ChildWorkflowExecutionTimedOutEventAttributes)2 EntityNotExistsError (com.uber.cadence.EntityNotExistsError)2 PollForActivityTaskResponse (com.uber.cadence.PollForActivityTaskResponse)2 PollForDecisionTaskResponse (com.uber.cadence.PollForDecisionTaskResponse)2 SignalExternalWorkflowExecutionFailedEventAttributes (com.uber.cadence.SignalExternalWorkflowExecutionFailedEventAttributes)2 StartChildWorkflowExecutionInitiatedEventAttributes (com.uber.cadence.StartChildWorkflowExecutionInitiatedEventAttributes)2 StartWorkflowExecutionRequest (com.uber.cadence.StartWorkflowExecutionRequest)2 WorkflowExecutionContinuedAsNewEventAttributes (com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes)2 WorkflowExecutionSignaledEventAttributes (com.uber.cadence.WorkflowExecutionSignaledEventAttributes)2 WorkflowExecutionStartedEventAttributes (com.uber.cadence.WorkflowExecutionStartedEventAttributes)2 TaskListId (com.uber.cadence.internal.testservice.TestWorkflowStore.TaskListId)2 ArrayList (java.util.ArrayList)2