/** * This method creates a FORK task and adds the list of dynamic fork tasks keyed by "forkedTaskDefs" and * their names keyed by "forkedTasks" into {@link Task#getInputData()} * * @param taskToSchedule A {@link WorkflowTask} representing {@link TaskType#FORK_JOIN_DYNAMIC} * @param workflowInstance: A instance of the {@link Workflow} which represents the workflow being executed. * @param taskId: The string representation of {@link java.util.UUID} which will be set as the taskId. * @param dynForkTasks: The list of dynamic forked tasks, the reference names of these tasks will be added to the forkDynamicTask * @return A new instance of {@link Task} representing a {@link SystemTaskType#FORK} */ @VisibleForTesting Task createDynamicForkTask(WorkflowTask taskToSchedule, Workflow workflowInstance, String taskId, List<WorkflowTask> dynForkTasks) { Task forkDynamicTask = new Task(); forkDynamicTask.setTaskType(SystemTaskType.FORK.name()); forkDynamicTask.setTaskDefName(SystemTaskType.FORK.name()); forkDynamicTask.setReferenceTaskName(taskToSchedule.getTaskReferenceName()); forkDynamicTask.setWorkflowInstanceId(workflowInstance.getWorkflowId()); forkDynamicTask.setCorrelationId(workflowInstance.getCorrelationId()); forkDynamicTask.setScheduledTime(System.currentTimeMillis()); forkDynamicTask.setEndTime(System.currentTimeMillis()); List<String> forkedTaskNames = dynForkTasks.stream() .map(WorkflowTask::getTaskReferenceName) .collect(Collectors.toList()); forkDynamicTask.getInputData().put("forkedTasks", forkedTaskNames); forkDynamicTask.getInputData().put("forkedTaskDefs", dynForkTasks); //TODO: Remove this parameter in the later releases forkDynamicTask.setTaskId(taskId); forkDynamicTask.setStatus(Task.Status.COMPLETED); forkDynamicTask.setWorkflowTask(taskToSchedule); return forkDynamicTask; }
public static boolean isBuiltIn(String taskType) { return is(taskType) && builtInTasks.contains(taskType); }
if (!task.getStatus().isRetriable() || SystemTaskType.isBuiltIn(task.getTaskType()) || taskDefinition == null || taskDefinition.getRetryCount() <= retryCount) { WorkflowStatus status = task.getStatus().equals(TIMED_OUT) ? WorkflowStatus.TIMED_OUT : WorkflowStatus.FAILED; updateWorkflowOutput(workflow, task);
if (SystemTaskType.is(pendingTask.getTaskType()) && !pendingTask.getStatus().isTerminal()) {
if (!task.getStatus().isRetriable() || SystemTaskType.isBuiltIn(task.getTaskType()) || taskDefinition == null || taskDefinition.getRetryCount() <= retryCount) { WorkflowStatus status = task.getStatus().equals(TIMED_OUT) ? WorkflowStatus.TIMED_OUT : WorkflowStatus.FAILED; updateWorkflowOutput(workflow, task);
@VisibleForTesting List<Task> getNextTask(Workflow workflow, Task task) { final WorkflowDef workflowDef = workflow.getWorkflowDefinition(); // Get the following task after the last completed task if (SystemTaskType.is(task.getTaskType()) && SystemTaskType.DECISION.name().equals(task.getTaskType())) { if (task.getInputData().get("hasChildren") != null) { return Collections.emptyList(); } } String taskReferenceName = task.getReferenceTaskName(); WorkflowTask taskToSchedule = workflowDef.getNextTask(taskReferenceName); while (isTaskSkipped(taskToSchedule, workflow)) { taskToSchedule = workflowDef.getNextTask(taskToSchedule.getTaskReferenceName()); } if (taskToSchedule != null) { return getTasksToBeScheduled(workflow, taskToSchedule, 0); } return Collections.emptyList(); }
public int requeuePendingTasks(String taskType) { int count = 0; List<Task> tasks = getPendingTasksForTaskType(taskType); for (Task pending : tasks) { if (SystemTaskType.is(pending.getTaskType())) { continue; } if (pending.getStatus().isTerminal()) { continue; } logger.info("Requeuing Task: workflowId=" + pending.getWorkflowInstanceId() + ", taskType=" + pending.getTaskType() + ", taskId=" + pending.getTaskId()); boolean pushed = requeue(pending); if (pushed) { count++; } } return count; }
@VisibleForTesting List<Task> getNextTask(Workflow workflow, Task task) { final WorkflowDef workflowDef = workflow.getWorkflowDefinition(); // Get the following task after the last completed task if (SystemTaskType.is(task.getTaskType()) && SystemTaskType.DECISION.name().equals(task.getTaskType())) { if (task.getInputData().get("hasChildren") != null) { return Collections.emptyList(); } } String taskReferenceName = task.getReferenceTaskName(); WorkflowTask taskToSchedule = workflowDef.getNextTask(taskReferenceName); while (isTaskSkipped(taskToSchedule, workflow)) { taskToSchedule = workflowDef.getNextTask(taskToSchedule.getTaskReferenceName()); } if (taskToSchedule != null) { return getTasksToBeScheduled(workflow, taskToSchedule, 0); } return Collections.emptyList(); }
private int requeuePendingTasks(Workflow workflow, long threshold) { int count = 0; List<Task> tasks = workflow.getTasks(); for (Task pending : tasks) { if (SystemTaskType.is(pending.getTaskType())) { continue; } if (pending.getStatus().isTerminal()) { continue; } if (pending.getUpdateTime() < threshold) { logger.info("Requeuing Task: workflowId=" + workflow.getWorkflowId() + ", taskType=" + pending.getTaskType() + ", taskId=" + pending.getTaskId()); long callback = pending.getCallbackAfterSeconds(); if (callback < 0) { callback = 0; } boolean pushed = queueDAO.pushIfNotExists(QueueUtils.getQueueName(pending), pending.getTaskId(), callback); if (pushed) { count++; } } } return count; }
/** * This method creates a JOIN task that is used in the {@link this#getMappedTasks(TaskMapperContext)} * at the end to add a join task to be scheduled after all the fork tasks * * @param workflowInstance: A instance of the {@link Workflow} which represents the workflow being executed. * @param joinWorkflowTask: A instance of {@link WorkflowTask} which is of type {@link TaskType#JOIN} * @param joinInput: The input which is set in the {@link Task#setInputData(Map)} * @return a new instance of {@link Task} representing a {@link SystemTaskType#JOIN} */ @VisibleForTesting Task createJoinTask(Workflow workflowInstance, WorkflowTask joinWorkflowTask, HashMap<String, Object> joinInput) { Task joinTask = new Task(); joinTask.setTaskType(SystemTaskType.JOIN.name()); joinTask.setTaskDefName(SystemTaskType.JOIN.name()); joinTask.setReferenceTaskName(joinWorkflowTask.getTaskReferenceName()); joinTask.setWorkflowInstanceId(workflowInstance.getWorkflowId()); joinTask.setWorkflowType(workflowInstance.getWorkflowName()); joinTask.setCorrelationId(workflowInstance.getCorrelationId()); joinTask.setScheduledTime(System.currentTimeMillis()); joinTask.setInputData(joinInput); joinTask.setTaskId(IDGenerator.generate()); joinTask.setStatus(Task.Status.IN_PROGRESS); joinTask.setWorkflowTask(joinWorkflowTask); return joinTask; }
private final Predicate<Task> isSystemTask = task -> SystemTaskType.is(task.getTaskType());
public static boolean isBuiltIn(String taskType) { return is(taskType) && builtInTasks.contains(taskType); }
sequence = new String[]{"junit_task_1", "junit_task_3"}; validate(wfid, sequence, new String[]{SystemTaskType.DECISION.name(), SystemTaskType.DECISION.name(), "junit_task_1", "junit_task_3", SystemTaskType.DECISION.name()}, 5); assertNotNull(wfid); sequence = new String[]{"junit_task_2"}; validate(wfid, sequence, new String[]{SystemTaskType.DECISION.name(), SystemTaskType.DECISION.name(), "junit_task_2", SystemTaskType.DECISION.name()}, 4); assertNotNull(wfid); sequence = new String[]{"junit_task_3", "junit_task_4"}; validate(wfid, sequence, new String[]{SystemTaskType.DECISION.name(), "junit_task_3", SystemTaskType.DECISION.name(), "junit_task_4"}, 3);
if (SystemTaskType.is(pendingTask.getTaskType()) && !pendingTask.getStatus().isTerminal()) {
assertEquals(SystemTaskType.FORK.name(),mappedTasks.get(0).getTaskType()); assertEquals(SystemTaskType.JOIN.name(), mappedTasks.get(3).getTaskType()); List<String> joinTaskNames = (List<String>)mappedTasks.get(3).getInputData().get("joinOn"); assertEquals("xdt1, xdt2", joinTaskNames.stream().collect(Collectors.joining(", ")));
public int requeuePendingTasks(String taskType) { int count = 0; List<Task> tasks = getPendingTasksForTaskType(taskType); for (Task pending : tasks) { if (SystemTaskType.is(pending.getTaskType())) { continue; } if (pending.getStatus().isTerminal()) { continue; } logger.info("Requeuing Task: workflowId=" + pending.getWorkflowInstanceId() + ", taskType=" + pending.getTaskType() + ", taskId=" + pending.getTaskId()); boolean pushed = requeue(pending); if (pushed) { count++; } } return count; }