Search in sources :

Example 1 with WorkflowExecutionContinuedAsNewEventAttributes

use of com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes 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 WorkflowExecutionContinuedAsNewEventAttributes

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

the class StateMachines method continueAsNewWorkflow.

private static void continueAsNewWorkflow(RequestContext ctx, WorkflowData data, ContinueAsNewWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedEventId) {
    StartWorkflowExecutionRequest sr = ctx.getWorkflowMutableState().getStartRequest();
    WorkflowExecutionContinuedAsNewEventAttributes a = new WorkflowExecutionContinuedAsNewEventAttributes();
    a.setInput(d.getInput());
    if (d.isSetExecutionStartToCloseTimeoutSeconds()) {
        a.setExecutionStartToCloseTimeoutSeconds(d.getExecutionStartToCloseTimeoutSeconds());
    } else {
        a.setExecutionStartToCloseTimeoutSeconds(sr.getExecutionStartToCloseTimeoutSeconds());
    }
    if (d.isSetTaskList()) {
        a.setTaskList(d.getTaskList());
    } else {
        a.setTaskList(sr.getTaskList());
    }
    if (d.isSetWorkflowType()) {
        a.setWorkflowType(d.getWorkflowType());
    } else {
        a.setWorkflowType(sr.getWorkflowType());
    }
    if (d.isSetTaskStartToCloseTimeoutSeconds()) {
        a.setTaskStartToCloseTimeoutSeconds(d.getTaskStartToCloseTimeoutSeconds());
    } else {
        a.setTaskStartToCloseTimeoutSeconds(sr.getTaskStartToCloseTimeoutSeconds());
    }
    a.setDecisionTaskCompletedEventId(decisionTaskCompletedEventId);
    HistoryEvent event = new HistoryEvent().setEventType(EventType.WorkflowExecutionContinuedAsNew).setWorkflowExecutionContinuedAsNewEventAttributes(a);
    ctx.addEvent(event);
}
Also used : StartWorkflowExecutionRequest(com.uber.cadence.StartWorkflowExecutionRequest) WorkflowExecutionContinuedAsNewEventAttributes(com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes) HistoryEvent(com.uber.cadence.HistoryEvent)

Aggregations

HistoryEvent (com.uber.cadence.HistoryEvent)2 WorkflowExecutionContinuedAsNewEventAttributes (com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes)2 StartWorkflowExecutionRequest (com.uber.cadence.StartWorkflowExecutionRequest)1 WorkflowExecution (com.uber.cadence.WorkflowExecution)1 WorkflowExecutionCloseStatus (com.uber.cadence.WorkflowExecutionCloseStatus)1