use of io.kestra.core.models.tasks.ResolvedTask in project kestra by kestra-io.
the class ExecutorService method handleKilling.
private Executor handleKilling(Executor executor) {
if (executor.getExecution().getState().getCurrent() != State.Type.KILLING) {
return executor;
}
List<ResolvedTask> currentTasks = executor.getExecution().findTaskDependingFlowState(ResolvedTask.of(executor.getFlow().getTasks()), ResolvedTask.of(executor.getFlow().getErrors()));
if (executor.getExecution().hasRunning(currentTasks) || executor.getExecution().hasCreated()) {
return executor;
}
Execution newExecution = executor.getExecution().withState(State.Type.KILLED);
return executor.withExecution(newExecution, "handleKilling");
}
use of io.kestra.core.models.tasks.ResolvedTask 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();
}
use of io.kestra.core.models.tasks.ResolvedTask in project kestra by kestra-io.
the class FlowableUtils method resolveEachTasks.
public static List<ResolvedTask> resolveEachTasks(RunContext runContext, TaskRun parentTaskRun, List<Task> tasks, String value) throws IllegalVariableEvaluationException {
String renderValue = runContext.render(value);
List<Object> values;
try {
values = MAPPER.readValue(renderValue, TYPE_REFERENCE);
} catch (JsonProcessingException e) {
throw new IllegalVariableEvaluationException(e);
}
List<Object> distinctValue = values.stream().distinct().collect(Collectors.toList());
long nullCount = distinctValue.stream().filter(Objects::isNull).count();
if (nullCount > 0) {
throw new IllegalVariableEvaluationException("Found '" + nullCount + "' null values on Each, " + "with values=" + Arrays.toString(values.toArray()));
}
ArrayList<ResolvedTask> result = new ArrayList<>();
for (Object current : distinctValue) {
for (Task task : tasks) {
try {
String resolvedValue = current instanceof String ? (String) current : MAPPER.writeValueAsString(current);
result.add(ResolvedTask.builder().task(task).value(resolvedValue).parentId(parentTaskRun.getId()).build());
} catch (JsonProcessingException e) {
throw new IllegalVariableEvaluationException(e);
}
}
}
return result;
}
use of io.kestra.core.models.tasks.ResolvedTask in project kestra by kestra-io.
the class WorkerTest method workerTask.
private WorkerTask workerTask(String sleep) {
Bash bash = Bash.builder().type(Bash.class.getName()).id("unit-test").commands(new String[] { "for i in $(seq 1 " + sleep + "); do echo $i; sleep 1; done" }).build();
Flow flow = Flow.builder().id(IdUtils.create()).namespace("io.kestra.unit-test").tasks(Collections.singletonList(bash)).build();
Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of());
ResolvedTask resolvedTask = ResolvedTask.of(bash);
return WorkerTask.builder().runContext(runContextFactory.of(ImmutableMap.of("key", "value"))).task(bash).taskRun(TaskRun.of(execution, resolvedTask)).build();
}
Aggregations