Search in sources :

Example 1 with StartChildWorkflowExecutionDecisionAttributes

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

the class WorkflowDecisionContext method startChildWorkflow.

Consumer<Exception> startChildWorkflow(StartChildWorkflowExecutionParameters parameters, Consumer<WorkflowExecution> executionCallback, BiConsumer<byte[], Exception> callback) {
    final StartChildWorkflowExecutionDecisionAttributes attributes = new StartChildWorkflowExecutionDecisionAttributes();
    attributes.setWorkflowType(parameters.getWorkflowType());
    String workflowId = parameters.getWorkflowId();
    if (workflowId == null) {
        workflowId = generateUniqueId();
    }
    attributes.setWorkflowId(workflowId);
    if (parameters.getDomain() == null) {
        // Could be removed as soon as server allows null for domain.
        attributes.setDomain(workflowContext.getDomain());
    } else {
        attributes.setDomain(parameters.getDomain());
    }
    attributes.setInput(parameters.getInput());
    if (parameters.getExecutionStartToCloseTimeoutSeconds() == 0) {
        // TODO: Substract time passed since the parent start
        attributes.setExecutionStartToCloseTimeoutSeconds(workflowContext.getExecutionStartToCloseTimeoutSeconds());
    } else {
        attributes.setExecutionStartToCloseTimeoutSeconds((int) parameters.getExecutionStartToCloseTimeoutSeconds());
    }
    if (parameters.getTaskStartToCloseTimeoutSeconds() == 0) {
        attributes.setTaskStartToCloseTimeoutSeconds(workflowContext.getDecisionTaskTimeoutSeconds());
    } else {
        attributes.setTaskStartToCloseTimeoutSeconds((int) parameters.getTaskStartToCloseTimeoutSeconds());
    }
    if (parameters.getChildPolicy() == null) {
        // TODO: Child policy from a parent as soon as it is available in the WorkflowExecutionStarted event
        // Or when server accepts null
        // attributes.setChildPolicy(workflowContext.getChildPolicy());
        attributes.setChildPolicy(ChildPolicy.TERMINATE);
    } else {
        attributes.setChildPolicy(parameters.getChildPolicy());
    }
    String taskList = parameters.getTaskList();
    TaskList tl = new TaskList();
    if (taskList != null && !taskList.isEmpty()) {
        tl.setName(taskList);
    } else {
        tl.setName(workflowContext.getTaskList());
    }
    attributes.setTaskList(tl);
    attributes.setWorkflowIdReusePolicy(parameters.getWorkflowIdReusePolicy());
    decisions.startChildWorkflowExecution(attributes);
    final OpenChildWorkflowRequestInfo context = new OpenChildWorkflowRequestInfo(executionCallback);
    context.setCompletionHandle(callback);
    scheduledExternalWorkflows.put(attributes.getWorkflowId(), context);
    return new ChildWorkflowCancellationHandler(attributes.getWorkflowId(), callback);
}
Also used : StartChildWorkflowExecutionDecisionAttributes(com.uber.cadence.StartChildWorkflowExecutionDecisionAttributes) TaskList(com.uber.cadence.TaskList)

Aggregations

StartChildWorkflowExecutionDecisionAttributes (com.uber.cadence.StartChildWorkflowExecutionDecisionAttributes)1 TaskList (com.uber.cadence.TaskList)1