List<TaskModel> getNextTask(WorkflowModel workflow, TaskModel task) {
        final WorkflowDef workflowDef = workflow.getWorkflowDefinition();

        // Get the following task after the last completed task
        if (systemTaskRegistry.isSystemTask(task.getTaskType())
                && (TaskType.TASK_TYPE_DECISION.equals(task.getTaskType())
                        || TaskType.TASK_TYPE_SWITCH.equals(task.getTaskType()))) {
            if (task.getInputData().get("hasChildren") != null) {
                return Collections.emptyList();
            }
        }

        String taskReferenceName =
                task.isLoopOverTask()
                        ? TaskUtils.removeIterationFromTaskRefName(task.getReferenceTaskName())
                        : task.getReferenceTaskName();
        WorkflowTask taskToSchedule = workflowDef.getNextTask(taskReferenceName);
        while (isTaskSkipped(taskToSchedule, workflow)) {
            taskToSchedule = workflowDef.getNextTask(taskToSchedule.getTaskReferenceName());
        }
        if (taskToSchedule != null && TaskType.DO_WHILE.name().equals(taskToSchedule.getType())) {
            // check if already has this DO_WHILE task, ignore it if it already exists
            String nextTaskReferenceName = taskToSchedule.getTaskReferenceName();
            if (workflow.getTasks().stream()
                    .anyMatch(
                            runningTask ->
                                    runningTask
                                            .getReferenceTaskName()
                                            .equals(nextTaskReferenceName))) {
                return Collections.emptyList();
            }
        }
        if (taskToSchedule != null) {
            return getTasksToBeScheduled(workflow, taskToSchedule, 0);
        }

        return Collections.emptyList();
    }
Updates the workflow output.

@param workflow the workflow instance
@param task if not null, the output of this task will be copied to workflow output if no
    output parameters are specified in the workflow definition if null, the output of the
    last task in the workflow will be copied to workflow output of no output parameters are
    specified in the workflow definition
core/src/main/java/com/netflix/conductor/core/execution/DeciderService.java