use of io.kestra.core.models.tasks.FlowableTask in project kestra by kestra-io.
the class ExecutorService method saveFlowableOutput.
private List<TaskRun> saveFlowableOutput(List<NextTaskRun> nextTaskRuns, Executor executor, TaskRun parentTaskRun) {
return nextTaskRuns.stream().map(throwFunction(t -> {
TaskRun taskRun = t.getTaskRun();
if (!(t.getTask() instanceof FlowableTask)) {
return taskRun;
}
FlowableTask<?> flowableTask = (FlowableTask<?>) t.getTask();
try {
RunContext runContext = runContextFactory.of(executor.getFlow(), t.getTask(), executor.getExecution(), t.getTaskRun());
taskRun = taskRun.withOutputs(flowableTask.outputs(runContext, executor.getExecution(), parentTaskRun) != null ? flowableTask.outputs(runContext, executor.getExecution(), parentTaskRun).toMap() : ImmutableMap.of());
} catch (Exception e) {
executor.getFlow().logger().warn("Unable to save output on taskRun '{}'", taskRun, e);
}
return taskRun;
})).collect(Collectors.toList());
}
use of io.kestra.core.models.tasks.FlowableTask in project kestra by kestra-io.
the class ExecutorService method childNextsTaskRun.
private List<TaskRun> childNextsTaskRun(Executor executor, TaskRun parentTaskRun) throws InternalException {
Task parent = executor.getFlow().findTaskByTaskId(parentTaskRun.getTaskId());
if (parent instanceof FlowableTask) {
FlowableTask<?> flowableParent = (FlowableTask<?>) parent;
List<NextTaskRun> nexts = flowableParent.resolveNexts(runContextFactory.of(executor.getFlow(), parent, executor.getExecution(), parentTaskRun), executor.getExecution(), parentTaskRun);
if (nexts.size() > 0) {
return this.saveFlowableOutput(nexts, executor, parentTaskRun);
}
}
return new ArrayList<>();
}
use of io.kestra.core.models.tasks.FlowableTask in project kestra by kestra-io.
the class GraphService method fillGraph.
private static void fillGraph(GraphCluster graph, List<Task> tasks, RelationType relationType, TaskRun parent, Execution execution, String value) throws IllegalVariableEvaluationException {
Iterator<Task> iterator = tasks.iterator();
AbstractGraphTask previous = graph.getRoot();
boolean isFirst = true;
while (iterator.hasNext()) {
Task currentTask = iterator.next();
for (TaskRun currentTaskRun : findTaskRuns(currentTask, execution, parent)) {
AbstractGraphTask currentGraph;
List<String> parentValues = null;
// we use the graph relation type by default but we change it to pass relation for case below
RelationType newRelation = graph.getRelationType();
if (relationType == RelationType.ERROR) {
newRelation = relationType;
} else if ((!isFirst && relationType != RelationType.PARALLEL && graph.getRelationType() != RelationType.DYNAMIC)) {
newRelation = relationType;
}
Relation relation = new Relation(newRelation, currentTaskRun == null ? value : currentTaskRun.getValue());
if (execution != null && currentTaskRun != null) {
parentValues = execution.findChildsValues(currentTaskRun, true);
}
// detect kind
if (currentTask instanceof FlowableTask) {
FlowableTask<?> flowableTask = ((FlowableTask<?>) currentTask);
currentGraph = flowableTask.tasksTree(execution, currentTaskRun, parentValues);
} else {
currentGraph = new GraphTask(currentTask, currentTaskRun, parentValues, relationType);
}
// add the node
graph.getGraph().addNode(currentGraph);
// link to previous one
if (previous != null) {
graph.getGraph().addEdge(previous instanceof GraphCluster ? ((GraphCluster) previous).getEnd() : previous, currentGraph instanceof GraphCluster ? ((GraphCluster) currentGraph).getRoot() : currentGraph, relation);
}
// change previous for current one to link
if (relationType != RelationType.PARALLEL) {
previous = currentGraph;
}
// link to end task
if (GraphService.isAllLinkToEnd(relationType)) {
graph.getGraph().addEdge(currentGraph instanceof GraphCluster ? ((GraphCluster) currentGraph).getEnd() : currentGraph, graph.getEnd(), new Relation());
}
isFirst = false;
if (!iterator.hasNext() && !isAllLinkToEnd(relationType)) {
graph.getGraph().addEdge(currentGraph instanceof GraphCluster ? ((GraphCluster) currentGraph).getEnd() : currentGraph, graph.getEnd(), new Relation());
}
}
}
}
use of io.kestra.core.models.tasks.FlowableTask in project kestra by kestra-io.
the class ExecutorService method childWorkerTaskResult.
private Optional<WorkerTaskResult> childWorkerTaskResult(Flow flow, Execution execution, TaskRun parentTaskRun) throws InternalException {
Task parent = flow.findTaskByTaskId(parentTaskRun.getTaskId());
if (parent instanceof FlowableTask) {
FlowableTask<?> flowableParent = (FlowableTask<?>) parent;
RunContext runContext = runContextFactory.of(flow, parent, execution, parentTaskRun);
// first find the normal ended child tasks and send result
Optional<WorkerTaskResult> endedTask = childWorkerTaskTypeToWorkerTask(flowableParent.resolveState(runContext, execution, parentTaskRun), parent, parentTaskRun);
if (endedTask.isPresent()) {
return endedTask;
}
// after if the execution is KILLING, we find if all already started tasks if finished
if (execution.getState().getCurrent() == State.Type.KILLING) {
// first notified the parent taskRun of killing to avoid new creation of tasks
if (parentTaskRun.getState().getCurrent() != State.Type.KILLING) {
return childWorkerTaskTypeToWorkerTask(Optional.of(State.Type.KILLING), parent, parentTaskRun);
}
// Then wait for completion (KILLED or whatever) on child taks to KILLED the parennt one.
List<ResolvedTask> currentTasks = execution.findTaskDependingFlowState(flowableParent.childTasks(runContext, parentTaskRun), FlowableUtils.resolveTasks(flowableParent.getErrors(), parentTaskRun));
List<TaskRun> taskRunByTasks = execution.findTaskRunByTasks(currentTasks, parentTaskRun);
if (taskRunByTasks.stream().filter(t -> t.getState().isTerninated()).count() == taskRunByTasks.size()) {
return childWorkerTaskTypeToWorkerTask(Optional.of(State.Type.KILLED), parent, parentTaskRun);
}
}
}
return Optional.empty();
}
Aggregations